local extension = Package:new("ysch5")
extension.extensionName = "ysch_Al"

local U = require "packages/utility/utility"

--[[
    铝宝智慧，新搓一个功能更多的隐匿
--]]

--- 隐匿函数，支持多层叠加隐匿，和用指定武将隐匿。
---@param player ServerPlayer @ 目标角色
---@param general? string @ 要隐匿成的武将，默认为hiddenone
---@param kingdom? string @ 要隐匿成的势力，默认与general相同
local AlEnterHidden = function (player,general,kingdom)
    local room = player.room
    local generalMark, deputyMark = player:getTableMark("__hidden_generals"), player:getTableMark("__hidden_deputys")
    room:sendLog({
        type = "#EnterHidden",
        from = player.id,
    })
    local skills = "hidden_skill&ysch_Al_hidden_skill"
    if player:getMark("__hidden_general") ~= 0 or player:getMark("__hidden_deputy") ~= 0 then
        table.insert(generalMark,player:getMark("__hidden_general"))
        room:setPlayerMark(player,"__hidden_generals",generalMark)
        if player:getMark("__hidden_deputy") ~= 0 then
            table.insert(deputyMark,player:getMark("__hidden_deputy"))
            room:setPlayerMark(player,"__hidden_deputys",deputyMark)
        end
        skills = skills .. "|#ysch_Al_hidden_skill&"
    end
    room:setPlayerMark(player, "__hidden_general", player.general)
    for _, s in ipairs(Fk.generals[player.general]:getSkillNameList(true)) do
        if player:hasSkill(s, true) then
            skills = skills.."|-"..s
        end
    end
    if player.deputyGeneral ~= "" then
        room:setPlayerMark(player, "__hidden_deputy", player.deputyGeneral)
        for _, s in ipairs(Fk.generals[player.deputyGeneral]:getSkillNameList(true)) do
            if player:hasSkill(s, true) then
            skills = skills.."|-"..s
            end
        end
    end
    if not general then general = "hiddenone" end
    player.general = general
    player.gender = General.Male
    room:broadcastProperty(player, "gender")
    if player.deputyGeneral ~= "" then
        player.deputyGeneral = ""
    end
    if not kingdom then kingdom = Fk.generals[general].kingdom end
    player.kingdom = kingdom
    room:setPlayerMark(player, "__hidden_record",
    {
        maxHp = player.maxHp,
        hp = player.hp,
    })
    player.maxHp = Fk.generals[general].maxHp
    player.hp = Fk.generals[general].hp
    for _, property in ipairs({"general", "deputyGeneral", "kingdom", "maxHp", "hp"}) do
        room:broadcastProperty(player, property)
    end
    room:handleAddLoseSkills(player, skills, nil, false, true)
end
local Al_hiddenSkill = fk.CreateTriggerSkill{
    name = "#ysch_Al_hidden_skill&",
    priority = 0.001,
    mute = true,
    refresh_events = {"fk.GeneralAppeared"},
    can_refresh = function (self, event, target, player, data)
        return #player:getTableMark("__hidden_generals") > 0 or #player:getTableMark("__hidden_deputys") > 0
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local generalMark, deputyMark = player:getTableMark("__hidden_generals"), player:getTableMark("__hidden_deputys")
        if #generalMark > 0 then
            room:setPlayerMark(player,"__hidden_general",generalMark[#generalMark])
            table.remove(generalMark,#generalMark)
            room:setPlayerMark(player,"__hidden_generals",generalMark)
        end
        if #deputyMark > 0 then
            room:setPlayerMark(player,"__hidden_deputys",deputyMark[#deputyMark])
            table.remove(deputyMark,#deputyMark)
            room:setPlayerMark(player,"__hidden_deputys",deputyMark)
        end
    end
}
Fk:addSkill(Al_hiddenSkill)
--- 变更战场
--- @param room Room @ 游戏房间
--- @param from? ServerPlayer @ 发起角色
--- @param tos ServerPlayer | ServerPlayer[] @ 进入或离开战场的角色（列表）
--- @param battle string @ 进入或离开的战场
--- @param skillName? string @ 技能名
local ChangeBattlefield = function (room,from,tos,battle,skillName)
    local Enter, Leave, Change = {}, {}, {}
    if tos.class then tos = { tos } end
    for _, cp in ipairs(tos) do
        if cp:getMark("@[:]Battlefield") ~= battle then
            if cp:getMark("@[:]Battlefield") ~= 0 then
                table.insert(Change,{cp.id,cp:getMark("@[:]Battlefield")})
            end
            table.insert(Enter,cp.id)
            room:setPlayerMark(cp,"@[:]Battlefield",battle)
        else
            table.insert(Leave,cp.id)
            room:setPlayerMark(cp,"@[:]Battlefield",0)
        end
    end
    if from then
        if #Enter > 0 then
            room:sendLog{type = "#EnterJiajuchengFrom-log",from = from.id,to = Enter,arg = battle,toast = true}
        end
        if #Leave > 0 then
            room:sendLog{type = "#LeaveJiajuchengFrom-log",from = from.id,to = Leave,arg = battle,toast = true,}
        end
    else
        if #Enter > 0 then
            room:sendLog{type = "#EnterJiajucheng-log",to = Enter,arg = battle,toast = true,}
        end
        if #Leave > 0 then
            room:sendLog{type = "#LeaveJiajucheng-log",to = Leave,arg = battle,toast = true,}
        end
    end
    for _, id in ipairs(Enter) do
        local player = room:getPlayerById(id)
        room.logic:trigger("fk.EnterBattlefield", player, {battle = battle,from = from,skillName = skillName})
    end
    for _, value in ipairs(Change) do
        local player = room:getPlayerById(value[1])
        local leaveBattle = value[2]
        room.logic:trigger("fk.LeaveBattlefield", player, {battle = leaveBattle,from = from,skillName = skillName})
    end
    for _, id in ipairs(Leave) do
        local player = room:getPlayerById(id)
        room.logic:trigger("fk.LeaveBattlefield", player, {battle = battle,from = from,skillName = skillName})
    end
end
Fk:loadTranslationTable{
    ["#EnterHidden"] = "%from 进入隐匿状态",
    ["ysch5"] = "云上沧海",--小包名
}
local zhouyu = General:new(extension, "ysch5__zhouyu", "wu", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch5__zhouyu"] = "周瑜",
    ["#ysch5__zhouyu"] = "炎神点阵",
    ["designer:ysch5__zhouyu"] = "RIN",
    ["cv:ysch5__zhouyu"] = "未知",
    ["illustrator:ysch5__zhouyu"] = "鬼画府",
}
local yunyong = fk.CreateTriggerSkill{
    name = "ysch5_yunyong",
    events = {fk.TurnEnd},
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(self.name) and #player.room.logic:getActualDamageEvents(1, function (e)
            return e.data[1].from == player and e.data[1].damageType == fk.FireDamage
        end, Player.HistoryTurn) > 0
    end,
    on_cost = function (self, event, target, player, data)
        local choice = player.room:askForChoice(player,{"#ysch5_yunyong_chiye","#ysch5_yunyong_yingzi","Cancel"},self.name,"#ysch5_yunyong")
        if choice ~= "Cancel" then
            self.cost_data = choice
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local choice = string.sub(self.cost_data,16)
        for i = 1, 50, 1 do
            local name = "ysch"..tostring(i).."_"..choice
            p(name)
            if not player:hasSkill(name) then
                room:handleAddLoseSkills(player,name)
                break
            end
        end
    end,
}
for loop = 1, 50, 1 do
    local chiye = fk.CreateActiveSkill{
        name = "ysch"..loop.."_chiye",
        card_num = 0,
        card_filter = Util.FalseFunc,
        target_num = 1,
        target_filter = function(self, to_select, selected, selected_cards)
            return #selected == 0
        end,
        mute = true,
        prompt = "#ysch5_chiye",
        can_use = function (self, player, card, extra_data)
            return player:usedSkillTimes(self.name,Player.HistoryPhase) == 0
        end,
        on_use = function(self, room, effect)
            local player = room:getPlayerById(effect.from)
            local target = room:getPlayerById(effect.tos[1])
            room:notifySkillInvoked(player,"ysch5_chiye","offensive")
            player:broadcastSkillInvoke("ysch5_chiye")
            room:damage{
                from = player,
                to = target,
                damage = 1,
                skillName = self.name,
                damageType = fk.FireDamage,
            }
            local skills = table.map(table.filter(player.player_skills, function (s)
                return s:isPlayerSkill(player) and s.visible
            end), Util.NameMapper)
            if player.dead or #skills == 0 then return end
            local tolose = room:askForChoice(player, skills, self.name, "#ysch5_chiye-lose", true)
            room:handleAddLoseSkills(player, "-"..tolose)
        end,
    }
    local yingzi = fk.CreateTriggerSkill{
        name = "ysch"..loop.."_yingzi",
        frequency = Skill.Compulsory,
        events = {fk.DrawNCards},
        mute = true,
        on_use = function(self, event, target, player, data)
            player.room:notifySkillInvoked(player,"ysch5_yingzi","drawcard")
            player:broadcastSkillInvoke("ysch5_yingzi")
            data.n = data.n + 1
        end,
    }
    local yingzi_maxcards = fk.CreateMaxCardsSkill{
        name = "#ysch"..loop.."_yingzi_maxcards",
        main_skill = yingzi,
        fixed_func = function(self, player)
            if player:hasShownSkill(yingzi) then
                return player.maxHp
            end
        end
    }
    yingzi:addRelatedSkill(yingzi_maxcards)
    if loop ~= 5 then
        Fk:addSkill(chiye)
        Fk:addSkill(yingzi)
    else
        zhouyu:addSkill(chiye)
        zhouyu:addSkill(yunyong)
        zhouyu:addRelatedSkill(yingzi)
    end
    Fk:loadTranslationTable{
        ["ysch"..loop.."_chiye"] = "炽业",
        [":ysch"..loop.."_chiye"] = "出牌阶段限一次，你可以对一名角色造成1点火焰伤害，然后你失去一个技能。",
        ["ysch"..loop.."_yingzi"] = "英姿",
        [":ysch"..loop.."_yingzi"] = "锁定技，摸牌阶段，你多摸一张牌；你的手牌上限等同于你的体力上限。",
    }
end
Fk:loadTranslationTable{
    ["#ysch5_chiye"] = "炽业：你可以对一名角色造成1点火焰伤害",
    ["#ysch5_chiye-lose"] = "炽业：请失去一个技能",
    ["ysch5_yunyong"] = "云涌",
    [":ysch5_yunyong"] = "你造成过火焰伤害的回合结束时，你可以获得一个：1.“炽业”；2.“英姿”。",
    ["#ysch5_yunyong"] = "是否发动 云涌，获得一个技能",
    ["#ysch5_yunyong_chiye"] = "获得一个“炽业”",
    ["#ysch5_yunyong_yingzi"] = "获得一个“英姿”",

    ["$ysch5_chiye1"] = "火莲绽江矶，炎映三千弱水。",
    ["$ysch5_chiye2"] = "奇志吞樯橹，潮平百万寇贼。",
    ["$ysch5_yunyong1"] = "行计以险，纵略以奇，敌虽百万亦戏之如犬豕。",
    ["$ysch5_yunyong2"] = "若生铸剑为犁之心，须有纵钺止戈之力。",
    ["$ysch5_yingzi1"] = "江东多锦绣，离火起曹贼毕，九州同忾。",
    ["$ysch5_yingzi2"] = "星火乘风，风助火势，其必成燎原之姿。",
}
local wolong = General:new(extension, "ysch5__wolong", "qun", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch5__wolong"] = "卧龙诸葛亮",
    ["#ysch5__wolong"] = "",
    ["designer:ysch5__wolong"] = "隐匿",
    ["cv:ysch5__wolong"] = "隐匿",
    ["illustrator:ysch5__wolong"] = "隐匿",
}
local sanying_hiddenSkill = fk.CreateTriggerSkill{
    name = "ysch5_sanying_hidden_skill&",
    global = true,
    priority = 0.001,
    refresh_events = {fk.GamePrepared},
    can_refresh = function (self, event, target, player, data)
        if not player:hasSkill("hidden_skill&") then return false end
        local general = Fk.generals[player:getMark("__hidden_general")]
        local deputy = Fk.generals[player:getMark("__hidden_deputy")]
        local skills1,skills2 = {},{}
        if general then
            skills1 = general:getSkillNameList(true)
        end
        if deputy then
            skills2 = deputy:getSkillNameList(true)
        end
        return table.contains(skills1,'ysch5_sanying') or table.contains(skills2,'ysch5_sanying')
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        AlEnterHidden(player,nil,"none")
        AlEnterHidden(player,nil,"none")
    end,
}
Fk:addSkill(sanying_hiddenSkill)
local sanying = fk.CreateTriggerSkill{
    name = "ysch5_sanying",
    events = {"fk.GeneralAppeared"},
    can_trigger = function (self, event, target, player, data)
        return target == player and player:hasShownSkill(self)
    end,
    mute = true,
    on_cost = Util.TrueFunc,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local animType = false
        local targets = table.filter(room:getOtherPlayers(player), function (p)
            return not p:hasSkill("fengliang")
        end)
        if #targets > 0 then
            local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#ysch5_sanying-choose", self.name, true)
            if #tos > 0 then
                room:notifySkillInvoked(player,self.name,"big")
                animType = true
                local to = room:getPlayerById(tos[1])
                room:handleAddLoseSkills(to,"fengliang")
            end
        end
        local sameGenerals = {}
        for _, value in ipairs({"zhugeliang","wolong","godzhugeliang","weizhugeliang","wuzhugeliang"}) do
            if Fk.same_generals[value] then
                table.insertTableIfNeed(sameGenerals,table.filter(Fk.same_generals[value], function(g)
                    return g ~= player.general and Fk.generals[g] ~= nil and not Fk.generals[g].hidden
                end))
            end
        end
        local result = room:askForCustomDialog(player, self.name,
        "packages/utility/qml/ChooseGeneralsAndChoiceBox.qml", {
            sameGenerals,
            {"OK"},
            "#ysch5_sanying-general",
            {},
            1,
            1
        })
        if result ~= "" then
            if not animType then
                room:notifySkillInvoked(player,self.name,"big")
            end
            local reply = json.decode(result)
            local general = reply.cards[1]
            room:findGeneral(general)
            room:changeHero(player, general, true, false, true, true)
        end
    end,
}
sanying.isHiddenSkill = true
wolong:addSkill(sanying)
if not Fk.skills["fengliang"] then
    local fengliang = fk.CreateTriggerSkill{
        name = "fengliang",
        anim_type = "defensive",
        events = {fk.EnterDying},
        frequency = Skill.Wake,
        can_trigger = function(self, event, target, player, data)
          return target == player and player:hasSkill(self) and
            player:usedSkillTimes(self.name, Player.HistoryGame) == 0
        end,
        can_wake = function(self, event, target, player, data)
          return player.dying
        end,
        on_use = function(self, event, target, player, data)
          local room = player.room
          room:changeMaxHp(player, -1)
          room:recover({
            who = player,
            num = 2 - player.hp,
            recoverBy = player,
            skillName = self.name
          })
          room:handleAddLoseSkills(player, "tiaoxin", nil, true, false)
          if player:hasSkill("kunfen", true) then
            if player.phase == Player.Finish and player:usedSkillTimes("kunfen", Player.HistoryPhase) > 0 then
              room:handleAddLoseSkills(player, "-kunfen", nil, false, true)
              local phase = room.logic:getCurrentEvent():findParent(GameEvent.Phase)
              if phase ~= nil then
                phase:addCleaner(function()
                  room:handleAddLoseSkills(player, "kunfenEx", nil, false, true)
                end)
              end
            else
              room:handleAddLoseSkills(player, "-kunfen|kunfenEx", nil, false, true)
            end
          end
        end,
    }
    Fk:addSkill(fengliang)
    local kunfen = fk.CreateTriggerSkill{
        name = "kunfen",
        anim_type = "drawcard",
        frequency = Skill.Compulsory,
        events = {fk.EventPhaseStart},
        can_trigger = function(self, event, target, player, data)
          return target == player and player:hasSkill(self) and player.phase == Player.Finish
        end,
        on_use = function(self, event, target, player, data)
          player.room:loseHp(player, 1, self.name)
          if player:isAlive() then
            player.room:drawCards(player, 2, self.name)
          end
        end,
    }
    Fk:addSkill(kunfen)
    local kunfenEx = fk.CreateTriggerSkill{
        name = "kunfenEx",
        anim_type = "drawcard",
        events = {fk.EventPhaseStart},
        can_trigger = function(self, event, target, player, data)
          return target == player and player:hasSkill(self) and player.phase == Player.Finish
        end,
        on_use = function(self, event, target, player, data)
          player.room:loseHp(player, 1, self.name)
          if player:isAlive() then
            player.room:drawCards(player, 2, self.name)
          end
        end,
    }
    Fk:addSkill(kunfenEx)
    Fk:loadTranslationTable{
        ["fengliang"] = "逢亮",
        [":fengliang"] = "觉醒技，当你进入濒死状态时，你减1点体力上限并将体力值回复至2点，然后获得技能〖挑衅〗，将技能〖困奋〗改为非锁定技。",
        ["kunfen"] = "困奋",
        [":kunfen"] = "锁定技，结束阶段开始时，你失去1点体力，然后摸两张牌。",
        ["kunfenEx"] = "困奋",
        [":kunfenEx"] = "结束阶段开始时，你可以失去1点体力，然后摸两张牌。",
    }
end
wolong:addRelatedSkill("fengliang")
Fk:loadTranslationTable{
    ["ysch5_sanying"] = "三应",
    [":ysch5_sanying"] = "隐匿。隐匿。隐匿。你登场时，可令一名其他角色获得“逢亮”。",
    ["#ysch5_sanying-choose"] = "是否发动 三应？令一名其他角色获得“逢亮”",
    ["#ysch5_sanying-general"] = "三应：请选择一张武将牌登场",
}
if not Fk.skills["jincui"] then
    local zhugeliang = General(extension, "wm__zhugeliang", "shu", 4, 7)
    zhugeliang.total_hidden = true
    local jincui = fk.CreateTriggerSkill{
    name = "jincui",
    anim_type = "control",
    frequency = Skill.Compulsory,
    mute = true,
    events = {fk.EventPhaseStart, fk.GameStart},
    can_trigger = function(self, event, target, player, data)
        if event == fk.GameStart then
        return player:hasSkill(self) and player:getHandcardNum() < 7
        elseif event == fk.EventPhaseStart then
        return target == player and player:hasSkill(self) and player.phase == Player.Start
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        if event == fk.GameStart then
        room:notifySkillInvoked(player, self.name, "drawcard")
        player:broadcastSkillInvoke(self.name)
        local n = 7 - player:getHandcardNum()
        if n > 0 then
            player:drawCards(n, self.name)
        end
        elseif event == fk.EventPhaseStart then
        room:notifySkillInvoked(player, self.name)
        player:broadcastSkillInvoke(self.name)
        local n = 0
        for _, id in ipairs(room.draw_pile) do
            if Fk:getCardById(id).number == 7 then
            n = n + 1
            end
        end
        player.hp = math.min(player.maxHp, math.max(n, 1))
        room:broadcastProperty(player, "hp")
        room:askForGuanxing(player, room:getNCards(player.hp))
        end
    end,
    }
    local qingshi = fk.CreateTriggerSkill{
    name = "qingshi",
    events = {fk.CardUsing},
    mute = true,
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(self) and player.phase == Player.Play and
        table.find(player.player_cards[Player.Hand], function(id) return Fk:getCardById(id).trueName == data.card.trueName end) and
        not table.contains(player:getTableMark("qingshi-turn"), data.card.trueName)
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local choice = room:askForChoice(player, {"qingshi1", "qingshi2", "qingshi3", "Cancel"},
        self.name, "#qingshi-invoke:::"..data.card:toLogString())
        if choice == "qingshi1" then
        local to = room:askForChoosePlayers(player, TargetGroup:getRealTargets(data.tos), 1, 1,
            "#qingshi1-choose:::"..data.card:toLogString(), self.name)
        if #to > 0 then
            self.cost_data = {choice, to}
            return true
        end
        elseif choice == "qingshi2" then
        local to = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player, false), Util.IdMapper), 1, 998,
        "#qingshi2-choose:::"..data.card:toLogString(), self.name)
        if #to > 0 then
            self.cost_data = {choice, to}
            return true
        end
        elseif choice == "qingshi3" then
        self.cost_data = {choice}
        return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        room:addTableMark(player, "qingshi-turn", data.card.trueName)
        if self.cost_data[1] == "qingshi1" then
        room:notifySkillInvoked(player, self.name, "offensive")
        player:broadcastSkillInvoke(self.name)
        data.extra_data = data.extra_data or {}
        data.extra_data.qingshi_data = data.extra_data.qingshi_data or {}
        table.insert(data.extra_data.qingshi_data, {player.id, self.cost_data[2][1]})
        elseif self.cost_data[1] == "qingshi2" then
        room:notifySkillInvoked(player, self.name, "support")
        player:broadcastSkillInvoke(self.name)
        local tos = self.cost_data[2]
        room:sortPlayersByAction(tos)
        for _, id in ipairs(tos) do
            local p = room:getPlayerById(id)
            if not p.dead then
            p:drawCards(1, self.name)
            end
        end
        elseif self.cost_data[1] == "qingshi3" then
        room:notifySkillInvoked(player, self.name, "drawcard")
        player:broadcastSkillInvoke(self.name)
        player:drawCards(3, self.name)
        room:invalidateSkill(player, self.name, "-turn")
        end
    end,

    on_lose = function(self, player)
        local room = player.room
        room:setPlayerMark(player, "qingshi-turn", 0)
        room:validateSkill(player, self.name, "-turn")
    end,
    }
    local qingshi_delay = fk.CreateTriggerSkill{
    name = "#qingshi_delay",
    events = {fk.DamageCaused},
    anim_type = "offensive",
    can_trigger = function(self, event, target, player, data)
        if player.dead or data.card == nil or data.chain then return false end
        local room = player.room
        local card_event = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
        if not card_event then return false end
        local use = card_event.data[1]
        if use.extra_data then
            local qingshi_data = use.extra_data.qingshi_data
            if qingshi_data then
            return table.find(qingshi_data, function (players)
                return players[1] == player.id and players[2] == data.to.id
            end)
            end
        end
    end,
    on_cost = Util.TrueFunc,
    on_use = function(self, event, target, player, data)
        player:broadcastSkillInvoke(qingshi.name)
        data.damage = data.damage + 1
    end,
    }
    local zhizhe = fk.CreateActiveSkill{
    name = "zhizhe",
    prompt = "#zhizhe-active",
    anim_type = "special",
    frequency = Skill.Limited,
    card_num = 1,
    target_num = 0,
    can_use = function(self, player)
        return player:usedSkillTimes(self.name, Player.HistoryGame) == 0
    end,
    card_filter = function(self, to_select, selected)
        return #selected == 0 and Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand
        and not Fk:getCardById(to_select).is_derived and to_select > 0
    end,
    on_use = function(self, room, effect)
        local c = Fk:getCardById(effect.cards[1], true)
        local toGain = room:printCard(c.name, c.suit, c.number)
        room:moveCards({
        ids = {toGain.id},
        to = effect.from,
        toArea = Card.PlayerHand,
        moveReason = fk.ReasonPrey,
        proposer = effect.from,
        skillName = self.name,
        moveVisible = false,
        })
    end
    }
    local zhizhe_delay = fk.CreateTriggerSkill{
    name = "#zhizhe_delay",
    mute = true,
    events = {fk.AfterCardsMove},
    can_trigger = function(self, event, target, player, data)
        local mark = player:getTableMark("zhizhe")
        if #mark == 0 then return false end
        local room = player.room
        local move_event = room.logic:getCurrentEvent()
        local parent_event = move_event.parent
        if parent_event and (parent_event.event == GameEvent.UseCard or parent_event.event == GameEvent.RespondCard) then
        local parent_data = parent_event.data[1]
        if parent_data.from == player.id then
            local card_ids = room:getSubcardsByRule(parent_data.card)
            local to_get = {}
            for _, move in ipairs(data) do
            if move.toArea == Card.DiscardPile then
                for _, info in ipairs(move.moveInfo) do
                local id = info.cardId
                if info.fromArea == Card.Processing and room:getCardArea(id) == Card.DiscardPile and
                table.contains(card_ids, id) and table.contains(mark, id) then
                    table.insertIfNeed(to_get, id)
                end
                end
            end
            end
            if #to_get > 0 then
            self.cost_data = to_get
            return true
            end
        end
        end
    end,
    on_cost = Util.TrueFunc,
    on_use = function(self, event, target, player, data)
        local room = player.room
        room:notifySkillInvoked(player, self.name)
        player:broadcastSkillInvoke(zhizhe.name)
        room:obtainCard(player, self.cost_data, true, fk.ReasonJustMove, player.id, "zhizhe")
    end,

    refresh_events = {fk.AfterCardsMove},
    can_refresh = Util.TrueFunc,
    on_refresh = function(self, event, target, player, data)
        local room = player.room
        local marked = player:getTableMark("zhizhe")
        local marked2 = player:getTableMark("zhizhe-turn")
        marked2 = table.filter(marked2, function (id)
        return room:getCardArea(id) == Card.PlayerHand and room:getCardOwner(id) == player
        end)
        for _, move in ipairs(data) do
        if move.to == player.id and move.toArea == Card.PlayerHand and move.skillName == zhizhe.name then
            for _, info in ipairs(move.moveInfo) do
            local id = info.cardId
            if room:getCardArea(id) == Card.PlayerHand and room:getCardOwner(id) == player then
                if info.fromArea == Card.Void then
                table.insertIfNeed(marked, id)
                else
                table.insert(marked2, id)
                end
                room:setCardMark(Fk:getCardById(id), "@@zhizhe-inhand", 1)
            end
            end
        elseif move.moveReason ~= fk.ReasonUse and move.moveReason ~= fk.ReasonResonpse then
            for _, info in ipairs(move.moveInfo) do
            local id = info.cardId
            table.removeOne(marked, id)
            end
        end
        end
        room:setPlayerMark(player, "zhizhe", marked)
        room:setPlayerMark(player, "zhizhe-turn", marked2)
    end,
    }
    local zhizhe_prohibit = fk.CreateProhibitSkill{
    name = "#zhizhe_prohibit",
    prohibit_use = function(self, player, card)
        local mark = player:getTableMark("zhizhe-turn")
        if #mark == 0 then return false end
        local cardList = card:isVirtual() and card.subcards or {card.id}
        return table.find(cardList, function (id) return table.contains(mark, id) end)
    end,
    prohibit_response = function(self, player, card)
        local mark = player:getMark("zhizhe-turn")
        if #mark == 0 then return false end
        local cardList = card:isVirtual() and card.subcards or {card.id}
        return table.find(cardList, function (id) return table.contains(mark, id) end)
    end,
    }
    qingshi:addRelatedSkill(qingshi_delay)
    zhizhe:addRelatedSkill(zhizhe_delay)
    zhizhe:addRelatedSkill(zhizhe_prohibit)
    zhugeliang:addSkill(jincui)
    zhugeliang:addSkill(qingshi)
    zhugeliang:addSkill(zhizhe)
    Fk:loadTranslationTable{
        ["wm__zhugeliang"] = "武诸葛亮",
        ["wm"] = "武",
        ["#wm__zhugeliang"] = "忠武良弼",
        ["designer:wm__zhugeliang"] = "韩旭",
        ["illustrator:wm__zhugeliang"] = "梦回唐朝",
        ["cv:wm__zhugeliang"] = "马洋",
        ["jincui"] = "尽瘁",
        [":jincui"] = "锁定技，游戏开始时，你将手牌补至7张。准备阶段，你的体力值调整为与牌堆中点数为7的游戏牌数量相等（至少为1）。"..
        "然后你观看牌堆顶X张牌（X为你的体力值），将这些牌以任意顺序放回牌堆顶或牌堆底。",
        ["qingshi"] = "情势",
        [":qingshi"] = "当你于出牌阶段内使用一张牌时（每种牌名每回合限一次），若手牌中有同名牌，你可以选择一项：1.令此牌对其中一个目标造成的伤害值+1："..
        "2.令任意名其他角色各摸一张牌；3.摸三张牌，然后此技能本回合失效。",
        ["zhizhe"] = "智哲",
        [":zhizhe"] = "限定技，出牌阶段，你可以复制一张手牌（衍生牌除外）。此牌因你使用或打出而进入弃牌堆后，你获得且本回合不能再使用或打出之。",
        ["qingshi-turn"] = "情势",
        ["#qingshi-invoke"] = "情势：请选择一项（当前使用牌为%arg）",
        ["qingshi1"] = "令此牌对其中一个目标伤害+1",
        ["qingshi2"] = "令任意名其他角色各摸一张牌",
        ["qingshi3"] = "摸三张牌，然后此技能本回合失效",
        ["#qingshi1-choose"] = "情势：令%arg对其中一名目标造成伤害+1",
        ["#qingshi2-choose"] = "情势：令任意名其他角色各摸一张牌",
        ["#qingshi_delay"] = "情势",
        ["#zhizhe_delay"] = "智哲",
        ["#zhizhe-active"] = "发动 智哲，选择一张手牌（衍生牌除外），获得一张此牌的复制",
        ["@@zhizhe-inhand"] = "智哲",
      
        ["$jincui1"] = "情记三顾之恩，亮必继之以死。",
        ["$jincui2"] = "身负六尺之孤，臣当鞠躬尽瘁。",
        ["$qingshi1"] = "兵者，行霸道之势，彰王道之实。",
        ["$qingshi2"] = "将为军魂，可因势而袭，其有战无类。",
        ["$zhizhe1"] = "轻舟载浊酒，此去，我欲借箭十万。",
        ["$zhizhe2"] = "主公有多大胆略，亮便有多少谋略。",
        ["~wm__zhugeliang"] = "天下事，了犹未了，终以不了了之……",
    }
end
if not Fk.skills["wentian"] then
    local zhugeliang = General(extension, "js__zhugeliang", "shu", 3)
    zhugeliang.total_hidden = true
    local wentian = fk.CreateViewAsSkill{
    name = "wentian",
    pattern = "fire_attack,nullification",
    interaction = function()
        local availableNames = { "fire_attack", "nullification" }
        local names = U.getViewAsCardNames(Self, "wentian", availableNames)
        if #names > 0 then
        return U.CardNameBox { choices = names, all_choices = availableNames }
        end
    end,
    card_filter = Util.FalseFunc,
    view_as = function(self, cards)
        if #cards ~= 0 or not self.interaction.data then return end
        local card = Fk:cloneCard(self.interaction.data)
        card.skillName = self.name
        return card
    end,
    before_use = function(self, player, use)
        local room = player.room
        local topCardId = room:getNCards(1)[1]

        use.card:addSubcard(topCardId)
        local cardColor = Fk:getCardById(topCardId).color
        if
        (use.card.name == "nullification" and cardColor ~= Card.Black) or
        (use.card.name == "fire_attack" and cardColor ~= Card.Red)
        then
        room:invalidateSkill(player, self.name, "-round")
        end
    end,
    enabled_at_play = Util.TrueFunc,
    enabled_at_response = function(self, player, response)
        return not response
    end,
    }
    local wentianTrigger = fk.CreateTriggerSkill{
    name = "#wentian_trigger",
    anim_type = "control",
    main_skill = wentian,
    events = {fk.EventPhaseStart},
    can_trigger = function(self, event, target, player, data)
        return
        target == player and
        player:hasSkill(wentian) and
        player:getMark("wentian_trigger-turn") == 0 and
        player.phase > 1 and player.phase < 8
    end,
    on_cost = function(self, event, target, player, data)
        return player.room:askForSkillInvoke(player, "wentian", data, "#wentian-ask:::" .. Util.PhaseStrMapper(player.phase))
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        room:setPlayerMark(player, "wentian_trigger-turn", 1)
        local topCardIds = U.turnOverCardsFromDrawPile(player, 5, self.name, false)

        local others = room:getOtherPlayers(player, false)
        if #others > 0 then
        local _, ret = room:askForUseActiveSkill(player, "ex__choose_skill", "#wentian-give", false, {
            targets = table.map(others, Util.IdMapper),
            min_c_num = 1,
            max_c_num = 1,
            min_t_num = 1,
            max_t_num = 1,
            pattern = tostring(Exppattern{ id = topCardIds }),
            skillName = "wentian",
            expand_pile = topCardIds,
        }, false)

        local toGive = ret and ret.cards[1] or topCardIds[1]
        table.removeOne(topCardIds, toGive)
        room:moveCardTo(
            toGive,
            Card.PlayerHand,
            ret and room:getPlayerById(ret.targets[1]) or room:getOtherPlayers(player)[1],
            fk.ReasonGive,
            "wentian",
            nil,
            false,
            player.id,
            nil,
            player.id
        )

        if player.dead then
            room:cleanProcessingArea(topCardIds, self.name)
            return false
        end
        end

        local result = room:askForGuanxing(player, topCardIds, nil, nil, "wentian", true)
        room:sendLog{
        type = "#GuanxingResult",
        from = player.id,
        arg = #result.top,
        arg2 = #result.bottom,
        }
        local moveInfos = {}
        if #result.top > 0 then
        table.insert(moveInfos, {
            ids = table.reverse(result.top),
            toArea = Card.DrawPile,
            moveReason = fk.ReasonJustMove,
            skillName = self.name,
            proposer = player.id,
            moveVisible = false,
            visiblePlayers = player.id,
            drawPilePosition = 1
        })
        end
        if #result.bottom > 0 then
        table.insert(moveInfos, {
            ids = result.bottom,
            toArea = Card.DrawPile,
            moveReason = fk.ReasonJustMove,
            skillName = self.name,
            proposer = player.id,
            moveVisible = false,
            visiblePlayers = player.id,
            drawPilePosition = -1
        })
        end
        room:moveCards(table.unpack(moveInfos))
    end,
    }
    local chushi = fk.CreateActiveSkill{
    name = "chushi",
    anim_type = "support",
    card_num = 0,
    prompt = "#chushi",
    target_num = function(self)
        return #table.filter(Fk:currentRoom().alive_players, function(p) return p.role == "lord" end) > 1 and 1 or 0
    end,
    can_use = function(self, player)
        return
        player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and
        table.find(Fk:currentRoom().alive_players, function(p) return p.role == "lord" end) and
        (
            not player:isKongcheng() or
            table.find(Fk:currentRoom().alive_players, function(p) return p.role == "lord" and not p:isKongcheng() end)
        )
    end,
    card_filter = Util.FalseFunc,
    target_filter = function(self, to_select, selected)
        if #table.filter(Fk:currentRoom().alive_players, function(p) return p.role == "lord" end) < 2 then
        return false
        end

        local target = Fk:currentRoom():getPlayerById(to_select)
        return #selected == 0 and target.role == "lord" and not (Self:isKongcheng() and target:isKongcheng())
    end,
    on_use = function(self, room, effect)
        local player = room:getPlayerById(effect.from)
        local targetId = #effect.tos > 0 and effect.tos[1] or table.find(room.alive_players, function(p) return p.role == "lord" end).id
        local target = room:getPlayerById(targetId)

        room:delay(1000)
        local targets = { player }
        if target ~= player then
        table.insert(targets, target)
        end

        room:doIndicate(player.id, table.map(targets, Util.IdMapper))
        local discussion = U.Discussion(player, table.filter(targets, function(p) return not p:isKongcheng() end), self.name)
        if discussion.color == "red" then
        local drawTargets = { player.id }
        if player ~= target then
            table.insert(drawTargets, target.id)
            room:sortPlayersByAction(drawTargets)
        end

        drawTargets = table.map(drawTargets, Util.Id2PlayerMapper)

        for _, p in ipairs(drawTargets) do
            p:drawCards(1, self.name)
        end

        local loopLock = 1
        repeat
            for _, p in ipairs(drawTargets) do
            p:drawCards(1, self.name)
            end

            loopLock = loopLock + 1
        until player:getHandcardNum() + (player ~= target and target:getHandcardNum() or 0) >= 7 or loopLock == 20
        elseif discussion.color == "black" then
        room:addPlayerMark(player, "@chushiBuff-round")
        end
    end,
    }
    local chushiBuff = fk.CreateTriggerSkill{
    name = "#chushi_buff",
    anim_type = "offensive",
    events = {fk.DamageCaused},
    can_trigger = function(self, event, target, player, data)
        return target == player and player:getMark("@chushiBuff-round") > 0 and data.damageType ~= fk.NormalDamage
    end,
    on_cost = Util.TrueFunc,
    on_use = function(self, event, target, player, data)
        data.damage = data.damage + player:getMark("@chushiBuff-round")
    end,
    }
    local yinlue = fk.CreateTriggerSkill{
    name = "yinlue",
    anim_type = "support",
    events = {fk.DamageInflicted},
    can_trigger = function(self, event, target, player, data)
        local availableDMGTypes = {fk.ThunderDamage, fk.FireDamage}
        return
        player:hasSkill(self) and
        table.contains(availableDMGTypes, data.damageType) and
        player:getMark("yinlueUsed" .. data.damageType .. "-round") == 0
    end,
    on_cost = function(self, event, target, player, data)
        local damageTypeTable = {
        [fk.FireDamage] = "fire_damage",
        [fk.ThunderDamage] = "thunder_damage",
        }
        local phase =  data.damageType == fk.FireDamage and "phase_draw" or "phase_discard"

        return player.room:askForSkillInvoke(
        player,
        self.name,
        data,
        "#yinlue-ask::" .. data.to.id .. ":" .. damageTypeTable[data.damageType] .. ":" .. phase
        )
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        room:setPlayerMark(player, "yinlueUsed".. data.damageType.. "-round", 1)
        if room.logic:getCurrentEvent():findParent(GameEvent.Turn, true) then
        local phase = data.damageType == fk.FireDamage and Player.Draw or Player.Discard
        player:gainAnExtraTurn(true, self.name, { phase_table = { phase } })
        end
        return true
    end,
    }
    chushi:addRelatedSkill(chushiBuff)
    wentian:addRelatedSkill(wentianTrigger)
    zhugeliang:addSkill(wentian)
    zhugeliang:addSkill(chushi)
    zhugeliang:addSkill(yinlue)
    Fk:loadTranslationTable{
    ["js__zhugeliang"] = "诸葛亮",
    ["#js__zhugeliang"] = "炎汉忠魂",
    ["illustrator:js__zhugeliang"] = "鬼画府",
    ["js"] = "江山",

    ["wentian"] = "问天",
    ["#wentian_trigger"] = "问天",
    [":wentian"] = "你可以将牌堆顶的牌当【无懈可击】/【火攻】使用，若此牌不为黑色/红色，本技能于本轮内失效；\
    每回合限一次，你的任意阶段开始时，你可以观看牌堆顶五张牌，然后将其中一张牌交给一名其他角色，其余牌以任意顺序置于牌堆顶或牌堆底。",
    ["chushi"] = "出师",
    [":chushi"] = "出牌阶段限一次，你可以和主公议事，若结果为：红色，你与其各摸一张牌，然后重复此摸牌流程，直到你与其手牌之和不小于7\
    （若此主公为你，则改为你重复摸一张牌直到你的手牌数不小于7）；黑色，当你于本轮内造成属性伤害时，此伤害+1。",
    ["yinlue"] = "隐略",
    [":yinlue"] = "每轮每项各限一次，当一名角色受到火焰/雷电伤害时，你可以防止此伤害，然后若此时在一名角色的回合内，\
    你于此回合结束后执行一个仅有摸牌/弃牌阶段的额外回合。",
    ["#wentian-ask"] = "你是否发动技能“问天”（当前为 %arg ）？",
    ["wentian_give"] = "问天给牌",
    ["#wentian-give"] = "问天：请选择其中一张牌交给一名其他角色",
    ["#chushi_buff"] = "出师",
    ["#chushi"] = "出师：你可以和主公议事，红色你与其摸牌，黑色你本轮属性伤害增加",
    ["@chushiBuff-round"] = "出师+",
    ["#yinlue-ask"] = "隐略：你可以防止 %dest 受到的 %arg 伤害，回合结束执行仅有 %arg2 的回合",
    }
end
if not Fk.skills["mou__huoji"] then
    local mou__wolong = General(extension, "mou__wolong", "shu", 3)
    mou__wolong.total_hidden = true
    local mou__huoji = fk.CreateActiveSkill{
    name = "mou__huoji",
    anim_type = "offensive",
    prompt = "#mou__huoji",
    frequency = Skill.Quest,
    card_num = 0,
    target_num = 1,
    mute = true,
    can_use = function(self, player)
        return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
    end,
    card_filter = Util.FalseFunc,
    target_filter = function(self, to_select, selected, selected_cards)
        return #selected == 0 and to_select ~= Self.id
    end,
    on_use = function(self, room, effect)
        local player = room:getPlayerById(effect.from)
        local target = room:getPlayerById(effect.tos[1])
        room:notifySkillInvoked(player, self.name)
        player:broadcastSkillInvoke(self.name, math.random(2))
        room:damage{
        from = player,
        to = target,
        damage = 1,
        damageType = fk.FireDamage,
        skillName = self.name,
        }
        local targets = {}
        for _, p in ipairs(room:getAlivePlayers()) do
        if p ~= player and p ~= target and p.kingdom == target.kingdom then
            table.insert(targets, p)
        end
        end
        for _, p in ipairs(targets) do
        if not p.dead then
            room:damage{
            from = player,
            to = p,
            damage = 1,
            damageType = fk.FireDamage,
            skillName = self.name,
            }
        end
        end
    end,
    }
    local mou__huoji_trigger = fk.CreateTriggerSkill{
    name = "#mou__huoji_trigger",
    main_skill = mou__huoji,
    mute = true,
    events = {fk.EventPhaseStart, fk.EnterDying},
    can_trigger = function(self, event, target, player, data)
        if target == player and player:hasSkill(mou__huoji) and not player:getQuestSkillState("mou__huoji") then
        if event == fk.EventPhaseStart then
            if player.phase == Player.Start then
            local room = player.room
            return player:getMark("@mou__huoji") >= #room.players
            end
        else
            return true
        end
        end
    end,
    on_cost = Util.TrueFunc,
    on_use = function(self, event, target, player, data)
        local room = player.room
        if event == fk.EventPhaseStart then
        player:broadcastSkillInvoke("mou__huoji", math.random(2))
        room:notifySkillInvoked(player, "mou__huoji", "special")
        room:updateQuestSkillState(player, "mou__huoji", false)
        room:handleAddLoseSkills(player, "-mou__huoji|-mou__kanpo|mou__guanxing|mou__kongcheng", nil, true, false)
        if player.general == "mou__wolong" then
            player.general = "mou__zhugeliang"
            room:broadcastProperty(player, "general")
        else
            player.deputyGeneral = "mou__zhugeliang"
            room:broadcastProperty(player, "deputyGeneral")
        end
        else
        player:broadcastSkillInvoke("mou__huoji", 3)
        room:notifySkillInvoked(player, "mou__huoji", "negative")
        room:updateQuestSkillState(player, "mou__huoji", true)
        room:setPlayerMark(player, "@mou__huoji", 0)
        end
        room:invalidateSkill(player, "mou__huoji")
    end,

    refresh_events = {fk.Damage},
    can_refresh = function (self, event, target, player, data)
        return target == player and player:hasSkill(mou__huoji) and not player:getQuestSkillState("mou__huoji") and data.damageType == fk.FireDamage
    end,
    on_refresh = function (self, event, target, player, data)
        player.room:addPlayerMark(player, "@mou__huoji", data.damage)
    end,

    on_lose = function(self, player)
        player.room:setPlayerMark(player, "@mou__huoji", 0)
    end,
    }
    local mou__kanpo = fk.CreateTriggerSkill{
    name = "mou__kanpo",
    anim_type = "control",
    events ={fk.RoundStart, fk.CardUsing},
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(self) then
        if event == fk.RoundStart then
            if player:getMark("@[private]$mou__kanpo") ~= 0 then return true end
            --local max_limit = table.contains({"m_1v2_mode", "m_2v2_mode", "brawl_mode"}, player.room.settings.gameMode) and 2 or 4
            local max_limit = 10
            return player:getMark("mou__kanpo_times") < max_limit
        else
            return target ~= player and table.contains(U.getPrivateMark(player, "$mou__kanpo"), data.card.trueName)
        end
        end
    end,
    on_cost = function(self, event, target, player, data)
        if event == fk.RoundStart then
        return true
        else
        local room = player.room
        if room:askForSkillInvoke(player, self.name, nil,
        "#mou__kanpo-invoke::"..target.id..":"..data.card:toLogString()) then
            room:doIndicate(player.id, {target.id})
            return true
        end
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        if event == fk.RoundStart then
        local all_names = player:getMark("mou__kanpo")
        if all_names == 0 then
            all_names = U.getAllCardNames("btd", true)
            room:setPlayerMark(player, "mou__kanpo", all_names)
        end
        local names = table.simpleClone(all_names)

        if player:getMark("@[private]$mou__kanpo") ~= 0 then
            for _, name in ipairs(U.getPrivateMark(player, "$mou__kanpo")) do
            table.removeOne(names, name)
            end
            room:setPlayerMark(player, "@[private]$mou__kanpo", 0)
        end
        --local max_limit = table.contains({"m_1v2_mode", "m_2v2_mode", "brawl_mode"}, room.settings.gameMode) and 2 or 4
        local max_limit = 10
        max_limit = max_limit - player:getMark("mou__kanpo_times")
        if max_limit > 0 then
            local mark = U.askForChooseCardNames(room, player, names, 1, max_limit, self.name, "#mou__kanpo-choice:::"..max_limit,
            all_names, true, true)
            if #mark > 0 then
            room:addPlayerMark(player, "mou__kanpo_times", #mark)
            U.setPrivateMark(player, "$mou__kanpo", mark)
            end
        end
        else
        local mark = U.getPrivateMark(player, "$mou__kanpo")
        table.removeOne(mark, data.card.trueName)
        if #mark > 0 then
            U.setPrivateMark(player, "$mou__kanpo", mark)
        else
            room:setPlayerMark(player, "@[private]$mou__kanpo", 0)
        end
        data.toCard = nil
        data.tos = {}
        player:drawCards(1, self.name)
        end
    end,

    on_lose = function (self, player)
        player.room:setPlayerMark(player, "@[private]$mou__kanpo", 0)
        player.room:setPlayerMark(player, "mou__kanpo_times", 0)
    end,
    }
    mou__huoji:addRelatedSkill(mou__huoji_trigger)
    mou__wolong:addSkill(mou__huoji)
    mou__wolong:addSkill(mou__kanpo)
    Fk:loadTranslationTable{
    ["mou__wolong"] = "谋卧龙诸葛亮",
    ["#mou__wolong"] = "忠武侯",
    ["mou"] = "谋",
    ["mou__huoji"] = "火计",
    [":mou__huoji"] = "使命技，出牌阶段限一次，你可以选择一名其他角色，对其及其同势力的其他角色各造成1点火焰伤害。<br>\
    <strong>成功</strong>：准备阶段，若你本局游戏对其他角色造成过至少X点火焰伤害（X为本局游戏人数），你失去〖火计〗〖看破〗，获得〖观星〗〖空城〗。<br>\
    <strong>失败</strong>：当你进入濒死状态时，使命失败。",
    ["mou__kanpo"] = "看破",
    [":mou__kanpo"] = "每轮开始时，你清除〖看破〗记录的牌名，然后你可以选择并记录任意个数与本轮清除牌名均不相同的"..
    "非装备牌的牌名。（每局限记录十个）"..
    "当其他角色使用与你记录牌名相同的牌时，你可以移除一个对应牌名的记录，然后令此牌无效并摸一张牌。",
    ["#mou__huoji"] = "发动 火计，选择一名角色，对所有与其势力相同的其他角色造成1点火焰伤害",
    ["#mou__kanpo-choice"] = "看破：你可选择%arg次牌名，其他角色使用同名牌时，你可令其无效<br>",
    ["#mou__kanpo-invoke"] = "看破：是否令 %dest 使用的%arg无效？",
    ["@[private]$mou__kanpo"] = "看破",
    ["@mou__huoji"] = "火计",

    ["$mou__huoji1"] = "区区汉贼，怎挡天火之威？",
    ["$mou__huoji2"] = "就让此火，再兴炎汉国祚。",
    ["$mou__huoji3"] = "吾虽有功，然终逆天命啊。",
    ["$mou__kanpo1"] = "知汝欲行此计，故已待之久矣。",
    ["$mou__kanpo2"] = "静思敌谋，以出应对之策。",
    ["~mou__wolong"] = "纵具地利，不得天时亦难胜也……",
    }
end
if not Fk.skills["mou__guanxing"] then
    local mou__zhugeliang = General(extension, "mou__zhugeliang", "shu", 3)
    mou__zhugeliang.total_hidden = true
    mou__zhugeliang.hidden = true
    local mou__guanxing = fk.CreateTriggerSkill{
    name = "mou__guanxing",
    derived_piles = "$mou__guanxing&",
    events = {fk.EventPhaseStart},
    can_trigger = function(self, event, target, player, data)
        if target == player and player:hasSkill(self) then
        if player.phase == Player.Start then
            return #player:getPile("$mou__guanxing&") > 0 or player:getMark("mou__guanxing_times") < 3
        elseif player.phase == Player.Finish then
            return #player:getPile("$mou__guanxing&") > 0 and player:getMark("mou__guanxing-turn") > 0
        end
        end
    end,
    on_cost = Util.TrueFunc,
    on_use = function(self, event, target, player, data)
        local room = player.room
        if player.phase == Player.Start then
        if #player:getPile("$mou__guanxing&") > 0 then
            room:moveCards({
            from = player.id,
            ids = player:getPile("$mou__guanxing&"),
            toArea = Card.DiscardPile,
            moveReason = fk.ReasonPutIntoDiscardPile,
            skillName = self.name,
            fromSpecialName = "$mou__guanxing&",
            })
            if player.dead then return false end
        end
        local n = 7 - 2*player:getMark("mou__guanxing_times")
        if n < 1 then return false end
        room:addPlayerMark(player, "mou__guanxing_times")
        player:addToPile("$mou__guanxing&", room:getNCards(n), false, self.name)
        if player.dead or #player:getPile("$mou__guanxing&") == 0 then return false end
        end
        local result = room:askForGuanxing(player, player:getPile("$mou__guanxing&"), nil, nil, self.name, true, {"$mou__guanxing&", "Top"})
        if #result.bottom > 0 then
        room:moveCards({
            ids = table.reverse(result.bottom),
            from = player.id,
            fromArea = Card.PlayerSpecial,
            toArea = Card.DrawPile,
            moveReason = fk.ReasonJustMove,
            skillName = self.name,
            fromSpecialName = "$mou__guanxing&",
        })
        room:sendLog{
            type = "#GuanxingResult",
            from = player.id,
            arg = #result.bottom,
            arg2 = 0,
        }
        elseif player.phase == Player.Start then
        room:setPlayerMark(player, "mou__guanxing-turn", 1)
        end
    end,

    on_lose = function (self, player)
        player.room:setPlayerMark(player, "mou__guanxing_times", 0)
    end,
    }
    local mou__kongcheng = fk.CreateTriggerSkill{
    name = "mou__kongcheng",
    mute = true,
    frequency = Skill.Compulsory,
    events = {fk.DamageInflicted},
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(self) and player:hasSkill("mou__guanxing", true)
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        player:broadcastSkillInvoke(self.name)
        if #player:getPile("$mou__guanxing&") > 0 then
        room:notifySkillInvoked(player, self.name, "defensive")
        local pattern = ".|1~"..(#player:getPile("$mou__guanxing&") - 1)
        if #player:getPile("$mou__guanxing&") < 2 then
            pattern = "FuckYoka"
        end
        local judge = {
            who = player,
            reason = self.name,
            pattern = pattern,
        }
        room:judge(judge)
        if judge.card.number < #player:getPile("$mou__guanxing&") then
            data.damage = data.damage - 1
        end
        else
        room:notifySkillInvoked(player, self.name, "negative")
        data.damage = data.damage + 1
        end
    end,
    }
    mou__zhugeliang:addSkill(mou__guanxing)
    mou__zhugeliang:addSkill(mou__kongcheng)
    Fk:loadTranslationTable{
    ["mou__zhugeliang"] = "谋诸葛亮",
    ["mou__guanxing"] = "观星",
    [":mou__guanxing"] = "准备阶段，你移去所有的“星”，并将牌堆顶的X张牌置于武将牌上"..
    "（X为7-此前此技能准备阶段发动次数的两倍），称为“星”，然后你可以将任意张“星”置于牌堆顶。"..
    "结束阶段，若你未于准备阶段将“星”置于牌堆顶，则你可以将任意张“星”置于牌堆顶。你可以如手牌般使用或打出“星”。",
    ["mou__kongcheng"] = "空城",
    [":mou__kongcheng"] = "锁定技，当你受到伤害时，若你拥有技能〖观星〗且你的武将牌上："..
    "有“星”，你判定，若结果点数不大于“星”数，则此伤害-1；没有“星”，此伤害+1。",
    ["$mou__guanxing&"] = "星",

    ["$mou__guanxing1"] = "明星皓月，前路通达。",
    ["$mou__guanxing2"] = "冷夜孤星，正如时局啊。",
    ["$mou__kongcheng1"] = "城下千军万马，我亦谈笑自若。",
    ["$mou__kongcheng2"] = "仲达可愿与我城中一叙？",
    ["~mou__zhugeliang"] = "琴焚身陨，功败垂成啊……",
    }
end
if not Fk.skills["mini__qixing"] then
    local mini__godzhugeliang = General(extension, "mini__godzhugeliang", "god", 3)
    mini__godzhugeliang.total_hidden = true
    local mini__qixing = fk.CreateTriggerSkill{
    name = "mini__qixing",
    anim_type = "defensive",
    events = {fk.EnterDying},
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryRound) == 0
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local judge = {
        who = player,
        reason = self.name,
        pattern = ".|8~13",
        }
        room:judge(judge)
        if judge.card.number > 7 and not player.dead then
        room:recover { num = 1, skillName = self.name, who = player, recoverBy = player}
        end
    end,
    }
    mini__godzhugeliang:addSkill(mini__qixing)
    local mini__tianfa = fk.CreateTriggerSkill{
    name = "mini__tianfa",
    anim_type = "offensive",
    events = {fk.TurnEnd, fk.CardUseFinished},
    can_trigger = function(self, event, target, player, data)
        if target == player and player:hasSkill(self) then
        if event == fk.CardUseFinished then
            return player.phase == Player.Play and data.card.type == Card.TypeTrick and player:getMark("mini__tianfa_count-turn") > 1
        else
            return player:getMark("@mini__punish-turn") > 0
        end
        end
    end,
    on_cost = function (self, event, target, player, data)
        if event == fk.CardUseFinished then return true end
        local n = player:getMark("@mini__punish-turn")
        local tos = player.room:askForChoosePlayers(player, table.map(player.room:getOtherPlayers(player, false), Util.IdMapper), 1, n, "#mini__tianfa-choose:::"..n, self.name, true)
        if #tos > 0 then
        self.cost_data = tos
        return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        if event == fk.CardUseFinished then
        room:setPlayerMark(player, "mini__tianfa_count-turn", 0)
        room:addPlayerMark(player, "@mini__punish-turn", 1)
        else
        local tos = self.cost_data
        room:sortPlayersByAction(tos)
        for _, pid in ipairs(tos) do
            local p = room:getPlayerById(pid)
            if not p.dead then
            room:damage { from = player, to = p, damage = 1, skillName = self.name }
            end
        end
        end
    end,

    refresh_events = {fk.CardUseFinished},
    can_refresh = function(self, event, target, player, data)
        return target == player and player:hasSkill(self) and player.phase == Player.Play and data.card.type == Card.TypeTrick
    end,
    on_refresh = function(self, event, target, player, data)
        player.room:addPlayerMark(player, "mini__tianfa_count-turn", 1)
    end,
    }
    mini__godzhugeliang:addSkill(mini__tianfa)
    local jifeng = fk.CreateActiveSkill{
        name = "mini_jifeng",
        anim_type = "drawcard",
        can_use = function(self, player)
          return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
        end,
        target_num = 0,
        card_num = 1,
        card_filter = function(self, to_select)
          return not Self:prohibitDiscard(Fk:getCardById(to_select)) and Fk:currentRoom():getCardArea(to_select) == Player.Hand
        end,
        on_use = function(self, room, effect)
          local from = room:getPlayerById(effect.from)
          room:throwCard(effect.cards, self.name, from, from)
          if from:isAlive() then
            local card = room:getCardsFromPileByRule(".|.|.|.|.|trick")
            if #card > 0 then
              room:obtainCard(from, card[1], true, fk.ReasonPrey)
            end
          end
        end,
    }
    mini__godzhugeliang:addSkill(jifeng)
    Fk:loadTranslationTable{
    ["mini__godzhugeliang"] = "神诸葛亮",
    ["mini"] = "小程序",
    ["mini__qixing"] = "七星",
    [":mini__qixing"] = "每轮限一次，当你进入濒死状态时，你可以进行判定，若判定结果的点数大于7，你回复1点体力。",
    ["mini__tianfa"] = "天罚",
    [":mini__tianfa"] = "你每于出牌阶段使用两张锦囊后，你于本回合内获得1枚“罚”标记。回合结束时，你可以对至多X名其他角色依次造成1点伤害（X为“罚”数）。",
    ["@mini__punish-turn"] = "罚",
    ["#mini__tianfa-choose"] = "天罚：你可以对至多 %arg 名其他角色依次造成1点伤害",
    ["mini_jifeng"] = "祭风", -- 神诸葛
    [":mini_jifeng"] = "出牌阶段限一次，你可弃置一张手牌，然后从牌堆中随机获得一张锦囊牌。",
    }
end
if not Fk.skills["os__beiding"] then
    local ifzhugeliang = General(extension, "os_if__zhugeliang", "shu", 3, 4)
    ifzhugeliang.total_hidden = true
    local ifzhugeliangwin = fk.CreateActiveSkill{ name = "os_if__zhugeliang_win_audio" }
    ifzhugeliangwin.package = extension
    Fk:addSkill(ifzhugeliangwin)
    Fk:loadTranslationTable{
    ["os_if__zhugeliang"] = "幻诸葛亮",
    ["os_if"] = "国际幻",
    ["#os_if__zhugeliang"] = "天意可叹",
    ["illustrator:os_if__zhugeliang"] = "黯荧岛",
    ["$os_if__zhugeliang_win_audio"] = "卧龙腾于九天，炎汉之火长明。",
    ["~os_if__zhugeliang"] = "先帝遗志未竟，吾怎可终于半途。",
    }

    ifzhugeliangwin = fk.CreateActiveSkill{ name = "os__beiding_names" }
    ifzhugeliangwin.package = extension
    Fk:addSkill(ifzhugeliangwin)

    local osBeiding = fk.CreateTriggerSkill{
    name = "os__beiding",
    anim_type = "control",
    events = {fk.EventPhaseStart},
    can_trigger = function (self, event, target, player, data)
        return target.phase == Player.Start and player:hasSkill(self) and player.hp > 0
    end,
    on_cost = function (self, event, target, player, data)
        local cardNames = U.getAllCardNames("bt")
        cardNames = table.filter(
        cardNames,
        function(name) return not table.contains(player:getTableMark("@$os__beiding_names"), name) end
        )

        local realNameMapper = {}
        for _, cardName in ipairs(cardNames) do
        local realNames = table.filter(cardNames, function(name) return name:endsWith("__" .. cardName) end)
        if #realNames > 0 then
            realNameMapper[cardName] = realNames
        end
        end
        cardNames = table.filter(cardNames, function(name) return #name:split("__") == 1 end)

        if #cardNames == 0 then
        return false
        end

        local room = player.room
        local namesChosen = room:askForChoices(player, cardNames, 1, player.hp, self.name, "#os__beiding-choose:::" .. player.hp)
        if #namesChosen == 0 then
        return false
        end

        for _, cardName in ipairs(namesChosen) do
        local realNames = realNameMapper[cardName]
        if realNames then
            table.insert(realNames, 1, cardName)
            local name = room:askForChoice(player, realNames, self.name, "#os__beiding-replace:::" .. cardName)
            local index = table.indexOf(namesChosen, cardName)
            table.remove(namesChosen, index)
            table.insert(namesChosen, index, name)
        end
        end

        self.cost_data = namesChosen
        return true
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local namesChosen = self.cost_data

        local namesChosenThisTurn = player:getTableMark("os__beiding_names-turn")
        table.insertTable(namesChosenThisTurn, namesChosen)
        room:setPlayerMark(player, "os__beiding_names-turn", namesChosenThisTurn)

        namesChosen = table.map(namesChosen, function(name)
        local realName = name:split("__")
        return realName[#realName]
        end)
        local beidingNames = player:getTableMark("@$os__beiding_names")
        table.insertTable(beidingNames, namesChosen)
        room:setPlayerMark(player, "@$os__beiding_names", beidingNames)

        if player:hasSkill("os_huan__beiding", true) then
        for _, id in ipairs(player:getCardIds("h")) do
            local card = Fk:getCardById(id)
            if table.contains(beidingNames, card.trueName) and card:getMark("@@os__beiding_card-inhand") ~= 1 then
            room:setCardMark(card, "@@os__beiding_card-inhand", 1)
            end
        end
        end
    end
    }
    local osBeidingUse = fk.CreateTriggerSkill{
    name = "#os__beiding_use",
    anim_type = "offensive",
    events = {fk.EventPhaseEnd},
    can_trigger = function (self, event, target, player, data)
        return target.phase == Player.Discard and player:getMark("os__beiding_names-turn") ~= 0
    end,
    on_cost = Util.TrueFunc,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local namesChosenThisTurn = player:getTableMark("os__beiding_names-turn")
        for _, name in ipairs(namesChosenThisTurn) do
        if not player:isAlive() then
            break
        end

        -- 牌名彩蛋
        local names = {"fire_attack", "fire__slash", "nullification"}
        if table.contains(names, name) then
            player:broadcastSkillInvoke("os__beiding_names", table.indexOf(names, name))
        end

        local use = U.askForUseVirtualCard(room, player, name, nil, self.name, "#os__beiding-use:::" .. name, false, true, true)
        if use and not table.contains(TargetGroup:getRealTargets(use.tos), target.id) and not target.dead then
            target:drawCards(1, self.name)
        end
        end
    end
    }
    Fk:loadTranslationTable{
    ["os__beiding"] = "北定",
    [":os__beiding"] = "一名角色的准备阶段开始时，你可以声明并记录至多X种未被〖北定〗记录过的基本牌或普通锦囊牌牌名。" ..
    "若如此做，此回合的弃牌阶段结束时，你视为依次使用本回合记录的牌（无距离限制），若此牌的目标不包含当前回合角色，" ..
    "其摸一张牌（X为你的体力值）。",
    ["#os__beiding_use"] = "北定",
    ["@$os__beiding_names"] = "北定",
    ["#os__beiding-choose"] = "北定：请选择至多%arg种牌名记录，你于此回合弃牌阶段结束时按顺序依次使用",
    ["#os__beiding-replace"] = "北定：请为牌名【%arg】替换具体牌名",
    ["#os__beiding-use"] = "北定：请视为使用【%arg】",

    ["$os__beiding1"] = "众将同心扶汉，北伐或可功成。",
    ["$os__beiding2"] = "虽失天时地利，亦有三分胜机！",

    -- 牌特殊语音
    ["$os__beiding_names1"] = "卧龙吐息之间，贼众灰飞烟灭！", -- 火攻
    ["$os__beiding_names2"] = "地火喑喑，焚将百万鱼龙！", -- 火杀
    ["$os__beiding_names3"] = "君臣将帅同心，敌必无可乘之机！", -- 无懈
    }

    osBeiding:addRelatedSkill(osBeidingUse)
    ifzhugeliang:addSkill(osBeiding)

    local osJielv = fk.CreateTriggerSkill{
    name = "os__jielv",
    anim_type = "support",
    events = {fk.TurnEnd, fk.Damaged, fk.HpLost},
    frequency = Skill.Compulsory,
    can_trigger = function (self, event, target, player, data)
        if not player:hasSkill(self) then
        return false
        end

        if event == fk.TurnEnd then
        return
            #player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function (e)
            local use = e.data[1]
            return use.from == player.id and table.contains(TargetGroup:getRealTargets(use.tos), target.id)
            end, Player.HistoryTurn) == 0
        end

        return target == player and player.maxHp < 7
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        if event == fk.TurnEnd then
        room:loseHp(player, 1, self.name)
        else
        room:changeMaxHp(player, math.min(event == fk.Damaged and data.damage or data.num, 7 - player.maxHp))
        end
    end
    }
    Fk:loadTranslationTable{
    ["os__jielv"] = "竭虑",
    [":os__jielv"] = "锁定技，一名角色的回合结束时，若你于本回合内未对其使用过牌，则你失去1点体力；当你受到1点伤害或失去1点体力后，" ..
    "若你的体力上限小于7，则你加1点体力上限。",

    ["$os__jielv1"] = "竭一国之材，尽万人之力！",
    ["$os__jielv2"] = "穷力尽心，亮定以血补天！",
    }

    ifzhugeliang:addSkill(osJielv)

    local osHunyou = fk.CreateTriggerSkill{
    name = "os__hunyou",
    anim_type = "defensive",
    events = {fk.AskForPeaches},
    frequency = Skill.Limited,
    can_trigger = function (self, event, target, player, data)
        return
        target == player and
        player:hasSkill(self) and
        player.hp < 1 and
        player:usedSkillTimes(self.name, Player.HistoryGame) == 0
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        if player.hp < 1 then
        room:recover{
            who = player,
            num = 1 - player.hp,
            recoverBy = player,
            skillName = self.name,
        }
        end

        room:setPlayerMark(player, "@@os__hunyou_prevent-turn", 1)
    end
    }
    local osHunyouBuff = fk.CreateTriggerSkill{
    name = "#os__hunyou_buff",
    anim_type = "defensive",
    events = {fk.DamageInflicted, fk.PreHpLost, fk.AfterTurnEnd},
    can_trigger = function (self, event, target, player, data)
        return player:getMark("@@os__hunyou_prevent-turn") > 0 and (event == fk.AfterTurnEnd or target == player)
    end,
    on_cost = Util.TrueFunc,
    on_use = function (self, event, target, player, data)
        if event == fk.AfterTurnEnd then
        local room = player.room
        room:handleAddLoseSkills(player, "-os__beiding|-os__jielv|-os__hunyou|os_huan__beiding|os_huan__jielv|os__huanji|os__changgui", nil, true, false)
        if player.general == "os_if__zhugeliang" then
            room:setPlayerProperty(player, "general", "os_if_huan__zhugeliang")
        end
        if player.deputyGeneral == "os_if__zhugeliang" then
            room:setPlayerProperty(player, "deputyGeneral", "os_if_huan__zhugeliang")
        end
        player:gainAnExtraTurn(true, "os__hunyou")
        else
        return true
        end
    end
    }
    Fk:loadTranslationTable{
    ["os__hunyou"] = "魂游",
    [":os__hunyou"] = "限定技，当你处于濒死状态时，你可以将体力回复至1点，本回合防止你受到的伤害和失去体力。" ..
    "此回合结束时，你<a href='os_ruhuan_zhugeliang'>“入幻”</a>并获得一个额外的回合。",
    ["os_ruhuan_zhugeliang"] = "变身为幻形态：<br><b>北定</b>：" ..
    "你使用〖北定〗记录的牌无距离限制且不计入次数；当你使用〖北定〗记录牌名的牌结算结束后，" ..
    "你摸一张牌，然后移除〖北定〗记录中的此牌名。<br>" ..
    "<b>竭虑</b>：锁定技，当你减1点体力上限后，你回复1点体力。<br>" ..
    "<b>幻计</b>：出牌阶段限一次，你可以减1点体力上限，在〖北定〗记录中增加X种牌名（X为你的体力值）。<br>" ..
    "<b>怅归</b>：锁定技，结束阶段开始时，若你的体力值为全场最低，则你<a href='os_tuihuan_zhugeliang'>“退幻”</a>并将体力上限调整至体力值。",
    ["#os__hunyou_buff"] = "魂游",
    ["@@os__hunyou_prevent-turn"] = "魂游",

    ["$os__hunyou1"] = "扶汉兴刘，夙夜沥血，忽入草堂梦中。",
    ["$os__hunyou2"] = "一整河山，以明己志，昔日言犹记否？",
    }

    osHunyou:addRelatedSkill(osHunyouBuff)
    ifzhugeliang:addSkill(osHunyou)

    local huanzhugeliang = General(extension, "os_if_huan__zhugeliang", "shu", 3, 4)
    huanzhugeliang.total_hidden = true
    huanzhugeliang.hidden = true
    local huanzhugeliangwin = fk.CreateActiveSkill{ name = "os_if_huan__zhugeliang_win_audio" }
    huanzhugeliangwin.package = extension
    Fk:addSkill(huanzhugeliangwin)
    Fk:loadTranslationTable{
    ["os_if_huan"] = "入幻",
    ["os_if_huan__zhugeliang"] = "幻诸葛亮",
    ["#os_if_huan__zhugeliang"] = "天意可叹",
    ["illustrator:os_if_huan__zhugeliang"] = "黯荧岛",
    ["$os_if_huan__zhugeliang_win_audio"] = "卧龙腾于九天，炎汉之火长明。",
    ["~os_if_huan__zhugeliang"] = "一人之愿，终难逆天命……",
    }

    huanzhugeliangwin = fk.CreateActiveSkill{ name = "os_huan__beiding_names" }
    huanzhugeliangwin.package = extension
    Fk:addSkill(huanzhugeliangwin)


    local osHuanBeiding = fk.CreateTriggerSkill{
    name = "os_huan__beiding",
    anim_type = "drawcard",
    events = {fk.CardUseFinished},
    mute = true,
    can_trigger = function (self, event, target, player, data)
        return
        target == player and
        player:hasSkill(self) and
        table.contains(player:getTableMark("@$os__beiding_names"), data.card.trueName)
    end,
    on_cost = Util.TrueFunc,
    on_use = function (self, event, target, player, data)
        local room = player.room
        room:notifySkillInvoked(player, self.name)
        -- 牌名彩蛋
        local names = {"fire_attack", "fire__slash", "nullification"}
        if table.contains(names, data.card.name) then
        player:broadcastSkillInvoke("os_huan__beiding_names", table.indexOf(names, data.card.name))
        else
        player:broadcastSkillInvoke(self.name)
        end
        player:drawCards(1, self.name)
        room:removeTableMark(player, "@$os__beiding_names", data.card.trueName)
        for _, id in ipairs(player:getCardIds("h")) do
        local card = Fk:getCardById(id)
        if card.trueName == data.card.trueName and card:getMark("@@os__beiding_card-inhand") == 1 then
            room:setCardMark(card, "@@os__beiding_card-inhand", 0)
        end
        end
    end,

    refresh_events = {fk.PreCardUse, fk.AfterCardsMove},
    can_refresh = function (self, event, target, player, data)
        if event == fk.PreCardUse then
        return
            target == player and
            player:hasSkill(self) and
            table.contains(player:getTableMark("@$os__beiding_names"), data.card.trueName)
        elseif event == fk.AfterCardsMove then
        return table.find(data, function(move)
            if move.to == player.id and move.toArea == Card.PlayerHand then
            return
                table.find(
                move.moveInfo,
                function(moveInfo)
                    return table.contains(player:getTableMark("@$os__beiding_names"), Fk:getCardById(moveInfo.cardId).trueName)
                end
                )
            end
        end)
        end
    end,
    on_refresh = function (self, event, target, player, data)
        if event == fk.PreCardUse then
        data.extraUse = true
        elseif event == fk.AfterCardsMove then
        for _, move in ipairs(data) do
            if move.to == player.id and move.toArea == Card.PlayerHand then
            for _, moveInfo in ipairs(move.moveInfo) do
                local card = Fk:getCardById(moveInfo.cardId)
                if table.contains(player:getTableMark("@$os__beiding_names"), card.trueName) then
                player.room:setCardMark(card, "@@os__beiding_card-inhand", 1)
                end
            end
            end
        end
        end
    end,

    on_acquire = function (self, player)
        for _, id in ipairs(player:getCardIds("h")) do
        local card = Fk:getCardById(id)
        if table.contains(player:getTableMark("@$os__beiding_names"), card.trueName) then
            player.room:setCardMark(card, "@@os__beiding_card-inhand", 1)
        end
        end
    end,
    on_lose = function (self, player)
        for _, id in ipairs(player:getCardIds("h")) do
        local card = Fk:getCardById(id)
        if card:getMark("@@os__beiding_card-inhand") ~= 0 then
            player.room:setCardMark(card, "@@os__beiding_card-inhand", 0)
        end
        end
    end,
    }
    local osHuanBeidingBuff = fk.CreateTargetModSkill{
    name = "#os_huan__beiding_buff",
    bypass_distances =  function(self, player, skill, card, to)
        return player:hasSkill(osHuanBeiding) and card:getMark("@@os__beiding_card-inhand") == 1
    end,
    }
    Fk:loadTranslationTable{
    ["os_huan__beiding"] = "北定",
    [":os_huan__beiding"] = "你使用〖北定〗记录的牌无距离限制且不计入次数；当你使用〖北定〗记录牌名的牌结算结束后，" ..
    "你摸一张牌，然后移除〖北定〗记录中的此牌名。",
    ["@@os__beiding_card-inhand"] = "北定",

    ["$os_huan__beiding1"] = "内外不懈如斯，长安不日可下！",
    ["$os_huan__beiding2"] = "先帝英灵冥鉴，此番定成夙愿！",

    -- 牌特殊语音
    ["$os_huan__beiding_names1"] = "炎龙归汉，燎尽不臣之贼！", -- 火攻
    ["$os_huan__beiding_names2"] = "天火离离，复光炎汉国祚！", -- 火杀
    ["$os_huan__beiding_names3"] = "亮善以谋制人，不为人谋所制！", -- 无懈
    }

    osHuanBeiding:addRelatedSkill(osHuanBeidingBuff)
    huanzhugeliang:addSkill(osHuanBeiding)

    local osHuanJielv = fk.CreateTriggerSkill{
    name = "os_huan__jielv",
    anim_type = "defensive",
    events = {fk.MaxHpChanged},
    frequency = Skill.Compulsory,
    can_trigger = function (self, event, target, player, data)
        return target == player and player:hasSkill(self) and data.num < 0 and player:isWounded()
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        room:recover{
        who = player,
        num = -data.num,
        recoverBy = player,
        skillName = self.name,
        }
    end
    }
    Fk:loadTranslationTable{
    ["os_huan__jielv"] = "竭虑",
    [":os_huan__jielv"] = "锁定技，当你减1点体力上限后，你回复1点体力。",

    ["$os_huan__jielv1"] = "出箕谷，饮河洛，所至长安！",
    ["$os_huan__jielv2"] = "破司马，废伪政，誓还帝都！",
    }

    huanzhugeliang:addSkill(osHuanJielv)

    local osHuanji = fk.CreateActiveSkill{
    name = "os__huanji",
    prompt = "#os__huanji-active",
    anim_type = "support",
    target_num = 0,
    card_num = 0,
    can_use = function(self, player)
        return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
    end,
    card_filter = Util.FalseFunc,
    target_filter = Util.FalseFunc,
    on_use = function(self, room, effect)
        local from = room:getPlayerById(effect.from)
        room:changeMaxHp(from, -1)
        if not from:isAlive() or from.hp < 1 then
        return
        end

        local cardNames = U.getAllCardNames("bt")
        cardNames = table.filter(
        cardNames,
        function(name) return not table.contains(from:getTableMark("@$os__beiding_names"), name) end
        )

        if #cardNames == 0 then
        return false
        end
        cardNames = table.filter(cardNames, function(name) return #name:split("__") == 1 end)

        local namesChosen = room:askForChoices(from, cardNames, from.hp, from.hp, self.name, "#os__beiding-choose:::" .. from.hp, false)
        local beidingNames = from:getTableMark("@$os__beiding_names")
        table.insertTable(beidingNames, namesChosen)
        room:setPlayerMark(from, "@$os__beiding_names", beidingNames)

        for _, id in ipairs(from:getCardIds("h")) do
        local card = Fk:getCardById(id)
        if table.contains(beidingNames, card.trueName) and card:getMark("@@os__beiding_card-inhand") ~= 1 then
            room:setCardMark(card, "@@os__beiding_card-inhand", 1)
        end
        end
    end
    }
    Fk:loadTranslationTable{
    ["os__huanji"] = "幻计",
    [":os__huanji"] = "出牌阶段限一次，你可以减1点体力上限，在〖北定〗记录中增加X种牌名（X为你的体力值）。",
    ["#os__huanji-active"] = "幻计：你可减1点体力上限为〖北定〗增加体力值数量的牌名记录",

    ["$os__huanji1"] = "以计中之计，调雍凉戴甲，天下备鞍！",
    ["$os__huanji2"] = "借计代兵，以一隅抗九州！",
    }

    huanzhugeliang:addSkill(osHuanji)

    local osChanggui = fk.CreateTriggerSkill{
    name = "os__changgui",
    anim_type = "negative",
    events = {fk.EventPhaseStart},
    frequency = Skill.Compulsory,
    can_trigger = function (self, event, target, player, data)
        return
        target == player and
        player.phase == Player.Finish and
        player:hasSkill(self) and
        table.every(player.room.alive_players, function(p) return p.hp >= player.hp end)
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        room:handleAddLoseSkills(player, "-os_huan__beiding|-os_huan__jielv|-os__huanji|-os__changgui|os__beiding|os__jielv|os__hunyou", nil, true, false)
        if player.general == "os_if_huan__zhugeliang" then
        room:setPlayerProperty(player, "general", "os_if__zhugeliang")
        end
        if player.deputyGeneral == "os_if_huan__zhugeliang" then
        room:setPlayerProperty(player, "deputyGeneral", "os_if__zhugeliang")
        end
        room:changeMaxHp(player, player.hp - player.maxHp)
    end
    }
    Fk:loadTranslationTable{
    ["os__changgui"] = "怅归",
    [":os__changgui"] = "锁定技，结束阶段开始时，若你的体力值为全场最低，则你<a href='os_tuihuan_zhugeliang'>“退幻”</a>并将体力上限调整至体力值。",

    ["os_tuihuan_zhugeliang"] = "变身为表形态：<br><b>北定</b>：" ..
    "一名角色的准备阶段开始时，你可以声明并记录至多X种未被〖北定〗记录过的基本牌或普通锦囊牌牌名。" .. 
    "若如此做，此回合的弃牌阶段结束时，你视为依次使用本回合记录的牌（无距离限制），若此牌的目标不包含当前回合角色，" ..
    "其摸一张牌（X为你的体力值）。<br>" ..
    "<b>竭虑</b>：锁定技，一名角色的回合结束时，若你于本回合内未对其使用过牌，则你失去1点体力；当你受到1点伤害或失去1点体力后，" ..
    "若你的体力上限小于7，则你加1点体力上限。" ..
    "<b>魂游</b>：限定技，当你处于濒死状态时，你可以将体力回复至1点，本回合防止你受到的伤害和体力流失。" ..
    "此回合结束时，你<a href='os_ruhuan_zhugeliang'>“入幻”</a>并获得一个额外的回合。",

    ["$os__changgui1"] = "隆中鱼水，永安星落，数载恍然隔世。",
    ["$os__changgui2"] = "铁马冰河，金台临望，倏醒方叹无功。",
    }

    huanzhugeliang:addSkill(osChanggui)
end
if not Fk.skills["yance"] then
    local function AddWinAudio(general)
        local Win = fk.CreateActiveSkill{ name = general.name.."_win_audio" }
        Win.package = extension
        Fk:addSkill(Win)
    end
    local friend__zhugeliang = General(extension, "m_friend__zhugeliang", "qun", 3)
    friend__zhugeliang.total_hidden = true
    AddWinAudio(friend__zhugeliang)
    Fk:loadTranslationTable{
    ["m_friend__zhugeliang"] = "友诸葛亮",
    ["m_friend"] = "友",
    ["#m_friend__zhugeliang"] = "龙骧九天",
    --["illustrator:m_friend__zhugeliang"] = "",
    ["~m_friend__zhugeliang"] = "吾既得明主，纵不得良时，亦当全力一试……",
    ["$m_friend__zhugeliang_win_audio"] = "鼎足之势若成，则将军中原可图也。",
    }
    local function DoYance(player)
    local room = player.room
    local results = table.simpleClone(player:getTableMark("yance_results"))
    local choices = table.contains({"red", "black"}, player:getMark("yance_guess")[1]) and {"red", "black"} or {"basic", "trick", "equip"}
    local fangqiu_trigger = 1
    if player:getMark("fangqiu_trigger") > 0 then
        room:setPlayerMark(player, "fangqiu_trigger", 0)
        if #player:getTableMark("yance_guess") == #player:getTableMark("yance_results") then
        fangqiu_trigger = 2
        end
    end
    room:setPlayerMark(player, "yance_guess", 0)
    room:setPlayerMark(player, "yance_results", 0)
    room:setPlayerMark(player, "@[yance]", 0)
    local yes = #table.filter(results, function (n)
        return n == 1
    end)
    if yes < #results / 2 then
        room:notifySkillInvoked(player, "yance", "negative")
        if yes == 0 then
        player:broadcastSkillInvoke("yance", 4)
        room:addPlayerMark(player, "yance_fail", fangqiu_trigger)
        room:loseHp(player, fangqiu_trigger, "yance")
        else
        player:broadcastSkillInvoke("yance", 6)
        end
        if not player.dead then
        room:askForDiscard(player, fangqiu_trigger, fangqiu_trigger, true, "yance", false)
        end
    else
        room:notifySkillInvoked(player, "yance", "drawcard")
        if yes == #results then
        player:broadcastSkillInvoke("yance", 3)
        else
        player:broadcastSkillInvoke("yance", 7)
        end
        local choice = room:askForChoice(player, choices, "yance", "#yance-prey")
        local pattern
        if table.contains({"basic", "trick", "equip"}, choice) then
        pattern = ".|.|.|.|.|"..choice
        elseif choice == "red" then
        pattern = ".|.|heart,diamond"
        elseif choice == "black" then
        pattern = ".|.|spade,club"
        end
        local cards = room:getCardsFromPileByRule(pattern, fangqiu_trigger, "drawPile")
        if #cards > 0 then
        room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonJustMove, "yance", nil, false, player.id)
        end
        if yes == #results and not player.dead then
        room:addPlayerMark(player, "yance_success", fangqiu_trigger)
        player:drawCards(1 + fangqiu_trigger, "yance")
        end
    end
    end
    local yance = fk.CreateTriggerSkill{
    name = "yance",
    mute = true,
    events = {fk.RoundStart, fk.EventPhaseStart},
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryRound) == 0 then
        if event == fk.RoundStart then
            return player.room:getBanner("RoundCount") == 1
        elseif event == fk.EventPhaseStart then
            return target == player and player.phase == Player.Start
        end
        end
    end,
    on_cost = function (self, event, target, player, data)
        local choice = player.room:askForChoice(player, {"yance_prey", "yance_yance", "Cancel"}, self.name)
        if choice ~= "Cancel" then
        self.cost_data = {choice = choice}
        return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        player:broadcastSkillInvoke("yance", table.random{1, 2})
        if self.cost_data.choice == "yance_prey" then
        room:notifySkillInvoked(player, "yance", "drawcard")
        local cards = room:getCardsFromPileByRule(".|.|.|.|.|trick", 1, "drawPile")
        if #cards > 0 then
            room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonJustMove, self.name, nil, false, player.id)
        end
        else
        room:notifySkillInvoked(player, "yance", "control")
        if player:getMark("yance_guess") ~= 0 then
            DoYance(player)
            if player.dead then return end
        end
        local n = 3
        n = n - player:getMark("yance_fail") + player:getMark("yance_success")
        if (room:isGameMode("1v2_mode") or room:isGameMode("2v2_mode")) then
            n = n + 1
        end
        if n < 1 then return end
        n = math.min(n, 7)
        local all_choices = {"basic", "trick", "equip", "red", "black"}
        local choice = room:askForChoice(player, all_choices, self.name, "#yance-choice:::1:"..n)
        room:addTableMark(player, "yance_guess", choice)
        local mark = {
            value = {choice},
        }
        room:setPlayerMark(player, "@[yance]", mark)
        if n > 1 then
            local choices = table.contains({"red", "black"}, choice) and {"red", "black"} or {"basic", "trick", "equip"}
            for i = 2, n, 1 do
            choice = room:askForChoice(player, choices, self.name, "#yance-choice:::"..i..":"..n, false, all_choices)
            room:addTableMark(player, "yance_guess", choice)
            table.insert(mark.value, choice)
            room:setPlayerMark(player, "@[yance]", mark)
            end
        end
        room.logic:trigger("fk.AfterYance", player, {})
        end
    end,
    }
    local yance_trigger = fk.CreateTriggerSkill{
    name = "#yance_trigger",
    mute = true,
    events = {fk.CardUsing},
    can_trigger = function(self, event, target, player, data)
        return player:getMark("yance_guess") ~= 0
    end,
    on_cost = Util.TrueFunc,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local result = 2
        local index = #player:getTableMark("yance_results") + 1
        local choice = player:getTableMark("yance_guess")[index]
        if data.card:getTypeString() == choice or data.card:getColorString() == choice then
        result = 1
        elseif (room:isGameMode("1v2_mode") or room:isGameMode("2v2_mode")) and index == 1 then
        result = 1
        end
        local mark = player:getTableMark("@[yance]")
        if result == 1 then
        table.insert(mark.value, 2 * index, "√")
        if #table.filter(player:getTableMark("yance_results"), function (n)
            return n == 1
        end) < 5 then
            player:broadcastSkillInvoke("yance", 5)
            room:notifySkillInvoked(player, "yance", "drawcard")
            player:drawCards(1, "yance")
            if player.dead then return end
        end
        else
        table.insert(mark.value, 2 * index, "×")
        end
        room:setPlayerMark(player, "@[yance]", mark)
        room:addTableMark(player, "yance_results", result)
        if #player:getTableMark("yance_guess") == #player:getTableMark("yance_results") then
        DoYance(player)
        end
    end,
    }
    Fk:addQmlMark{
    name = "yance",
    qml_path = function(name, value, p)
        if (value.players == nil and Self == p) or (value.players and table.contains(value.players, Self.id)) then
        return "packages/ysch_Al/qml/yance"
        end
        return ""
    end,
    how_to_show = function(name, value, p)
        if type(value) ~= "table" then return " " end
        return tostring(#table.filter(value.value, function (s)
        return s ~= "√" and s ~= "×"
        end))
    end,
    }
    yance:addRelatedSkill(yance_trigger)
    friend__zhugeliang:addSkill(yance)
    Fk:loadTranslationTable{
    ["yance"] = "演策",
    [":yance"] = "每轮限一次，首轮开始时，或准备阶段，你可以选择一项：从牌堆中随机获得一张锦囊牌；执行<a href='wolongyance'>“卧龙演策”</a>。"..
    "若你执行“卧龙演策”，当一张牌被使用时，若此牌的类别或颜色与你的预测相同，你摸一张牌（每次执行“卧龙演策”至多因此摸五张牌）。<br>"..
    "当“卧龙演策”的预测全部验证后，或当你再次执行“卧龙演策”时，若你本次“卧龙演策”正确的预测数量：<br>"..
    "为0，你失去1点体力，此后“卧龙演策”可预测的牌数-1；<br>"..
    "不足一半，你弃置一张牌；<br>"..
    "至少一半（向上取整），你根据本次预测的方式，从牌堆中获得一张符合你声明条件的牌；<br>"..
    "全部正确，你摸两张牌，此后“卧龙演策”可预测的牌数+1（至多为7）。",
    ["wolongyance"] = "预测此后被使用的指定数量张牌的颜色或类别（初始可预测的牌数为3），“预测的方式”即通过颜色预测或通过类别预测。"..
    "此预测在一名角色使用牌时揭示，若所有预测均已揭示，称为全部验证。",
    ["yance_prey"] = "获得一张锦囊牌",
    ["yance_yance"] = "执行“卧龙演策”",
    ["#yance-choice"] = "演策：预测将被使用的牌（第%arg张，共%arg2张）",
    ["@[yance]"] = "卧龙演策",
    ["#yance_trigger"] = "演策",
    ["#yance-prey"] = "演策：获得一张符合声明条件的牌",

    ["$yance1"] = "以今日之时局，唯以此策解之。",
    ["$yance2"] = "今世变化难测，需赖以演策之术。",
    ["$yance3"] = "百策百中，勤在推演而已。",
    ["$yance4"] = "哎，算计百般，终是徒劳。",
    ["$yance5"] = "所谓算无遗策，亦不过如此而已。",
    ["$yance6"] = "吾已尽全力，奈何老天仍胜我一筹。",
    ["$yance7"] = "未思周密，使敌有残喘之机。",
    }
    local fangqiu = fk.CreateTriggerSkill{
        name = "fangqiu",
        anim_type = "special",
        frequency = Skill.Limited,
        events = {"fk.AfterYance"},
        can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
        end,
        on_cost = function (self, event, target, player, data)
        return player.room:askForSkillInvoke(player, self.name, nil, "#fangqiu-invoke")
        end,
        on_use = function (self, event, target, player, data)
        local room = player.room
        room:setPlayerMark(player, "fangqiu_trigger", 1)
        local mark = player:getMark("@[yance]")
        mark.players = table.map(room.players, Util.IdMapper)
        room:setPlayerMark(player, "@[yance]", mark)
        end,
    }
    friend__zhugeliang:addSkill(fangqiu)
    Fk:loadTranslationTable{
        ["fangqiu"] = "方遒",
        [":fangqiu"] = "限定技，当你执行“卧龙演策”后，你可以展示你的“卧龙演策”预测，若如此做，本次“卧龙演策”的预测全部验证后，执行效果的值均+1。",
        ["#fangqiu-invoke"] = "方遒：是否令本次“卧龙演策”预测公开？全部验证后执行的效果+1",
    
        ["$fangqiu1"] = "一举可成之事，何必再增变数。",
        ["$fangqiu2"] = "破敌便在此刻，吾等勿负良机。",
        ["$fangqiu3"] = "哈哈哈哈，果不出我所料。",
    }
    local zhugeliang__gongli = fk.CreateTriggerSkill{
        name = "zhugeliang__gongli",
        frequency = Skill.Compulsory,
    }
    friend__zhugeliang:addSkill(zhugeliang__gongli)
    Fk:loadTranslationTable{
        ["zhugeliang__gongli"] = "共砺",
        [":zhugeliang__gongli"] = "锁定技，若为斗地主或2v2，你执行“卧龙演策”初始可预测的牌数+1；"..
        "若为斗地主或2v2，你“卧龙演策”预测的第一张牌的结果始终视为正确。（仅斗地主和2v2模式生效）",
        [":zhugeliang__gongli_pangtong"] = "锁定技，若友方友庞统在场，你执行“卧龙演策”初始可预测的牌数+1。",
        [":zhugeliang__gongli_xushu"] = "锁定技，若友方友徐庶在场，你“卧龙演策”预测的第一张牌的结果始终视为正确。",
        ["$zhugeliang__gongli1"] = "其志远兮，当与诤友共进。",
        ["$zhugeliang__gongli2"] = "共以济世为志，今与诸兄勉之。",
    }
end

local pangtong = General:new(extension, "ysch5__pangtong", "wei", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch5__pangtong"] = "庞统",
    ["#ysch5__pangtong"] = "凤锁连江",
    ["designer:ysch5__pangtong"] = "铝&独孤妙妙",
    ["cv:ysch5__pangtong"] = "未知",
    ["illustrator:ysch5__pangtong"] = "未知",
}
local zhoushi = fk.CreateTriggerSkill{
    name = "ysch5_zhoushi",
    refresh_events = {fk.CardUsing,fk.RoundStart,fk.ChainStateChanged},
    can_refresh = function (self, event, target, player, data)
        if event == fk.CardUsing then
            return data.card.trueName == "slash"
        else
            return true
        end
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local num1, num2 = 0, 0
        for _, cp in ipairs(room.alive_players) do
            if cp.chained or cp:getMark("ysch5_zhoushi_chained-round") > 0 then
                num1 = num1 + 1
                num2 = num2 + #room.logic:getEventsOfScope(GameEvent.UseCard, 999, function (e)
                    local use = e.data[1]
                    return use.from == cp.id and use.card.trueName == "slash"
                end, Player.HistoryRound)
                room:setPlayerMark(cp,"ysch5_zhoushi_chained-round",1)
            end
        end
        if player:hasSkill(self.name) then
            for _, cp in ipairs(room.alive_players) do
                if cp.chained or cp:getMark("ysch5_zhoushi_chained-round") > 0 then
                    room:setPlayerMark(cp,"@ysch5_zhoushi-round",tostring(num1-num2))
                end
            end
            if event == fk.CardUsing and target.chained then
                if tonumber(target:getMark("@ysch5_zhoushi-round")) > 0 then
                    target:addCardUseHistory("slash",-1)
                end
                room:notifySkillInvoked(player,self.name,"offensive")
            end
        end
    end,
}
local zhoushi_targetmod = fk.CreateTargetModSkill{
    name = "#ysch5_zhoushi_targetmod",
    fix_times_func = function(self, player, skill, scope)
        if (player.chained or player:getMark("ysch5_zhoushi_chained-round") > 0) and skill.trueName == "slash_skill" and scope == Player.HistoryPhase then
            return tonumber(player:getMark("@ysch5_zhoushi-round"))
        end
    end,
}
zhoushi:addRelatedSkill(zhoushi_targetmod)
pangtong:addSkill(zhoushi)
local lianhuan = fk.CreateActiveSkill{
    name = "ysch5_lianhuan",
    anim_type = "offensive",
    interaction = function (self, player)
        return U.CardNameBox { choices = {"fire_attack","iron_chain"}}
    end,
    card_filter = function(self, to_select)
        local card = Fk:getCardById(to_select)
        return card.suit == Card.Club
    end,
    min_target_num = 1,
    target_filter = function (self, to_select, selected, selected_cards, card, extra_data, player)
        if self.interaction.data == nil then return false end
        local to_use = Fk:cloneCard(self.interaction.data)
        to_use.skillName = self.name
        if player:isProhibited(Fk:currentRoom():getPlayerById(to_select), to_use) then return false end
        return #selected < #selected_cards and to_use.skill:targetFilter(to_select, {}, {}, to_use, Util.DummyTable, player)
    end,
    feasible = function(self, selected, selected_cards)
        if self.interaction.data == nil then return false end
        return #selected > 0 and #selected == #selected_cards
    end,
    on_use = function (self, room, effect)
        local player = room:getPlayerById(effect.from)
        room:recastCard(effect.cards,player,self.name)
        local card = Fk:cloneCard(self.interaction.data)
        card.skillName = self.name
        local use = {
            from = player.id,
            tos = table.map(effect.tos, function (id)
                return {id}
            end),
            card = card,
        }
        room:useCard(use)
        ChangeBattlefield(room,player,table.map(effect.tos, function (id)
            return room:getPlayerById(id)
        end),"ysch5_chibi",self.name)
    end,
}
pangtong:addSkill(lianhuan)
local chibi = fk.CreateTriggerSkill{
    name = "#ysch5_chibi",
    events = {fk.BeforeChainStateChange,"fk.EnterBattlefield","fk.LeaveBattlefield"},
    mute = true,
    global = true,
    can_trigger = function (self, event, target, player, data)
        if event == fk.BeforeChainStateChange then
            local num = player.room:getBanner("ysch5_chibi")
            if target == player and player.chained and not player.dead then
                return (num == 1 and player:getMark("@[:]Battlefield") == "ysch5_chibi") or (num == 2 and player:getMark("@[:]Battlefield") ~= "ysch5_chibi")
            end
        else
            return target == player and data.battle == "ysch5_chibi"
        end
    end,
    on_cost = Util.TrueFunc,
    frequency = Skill.Compulsory,
    priority = 0.001,
    on_use = function (self, event, target, player, data)
        local room = player.room
        if event == fk.BeforeChainStateChange then
            return true
        else
            local num = room:getBanner("ysch5_chibi") or 1
            num = num + 1
            if num > 3 then num = 1 end
            room:setBanner("ysch5_chibi",num)
            room:setBanner("@[:]ysch5_chibi", "ysch5_chibi"..tostring(num))
            if num == 1 then
                for _, cp in ipairs(room.alive_players) do
                    if cp:getMark("@[:]Battlefield") == "ysch5_chibi" then
                        cp:setChainState(true)
                    end
                end
            elseif num == 2 then
                for _, cp in ipairs(room.alive_players) do
                    if cp:getMark("@[:]Battlefield") ~= "ysch5_chibi" then
                        cp:setChainState(true)
                    end
                end
            elseif num == 3 then
                local targets = {}
                for _, cp in ipairs(room.alive_players) do
                    if cp:getMark("@[:]Battlefield") == "ysch5_chibi" then
                        table.insert(targets,cp)
                    end
                end
                if #targets > 0 then
                    for _, cp in ipairs(targets) do
                        room:damage({to = cp, damage = 1, damageType = fk.FireDamage, skillName = self.name})
                    end
                end
            end
        end
    end,
}
Fk:addSkill(chibi)
Fk:loadTranslationTable{
    ["ysch5_zhoushi"] = "舟师",
    [":ysch5_zhoushi"] = "锁定技，本轮横置过的角色使用【杀】次数上限为X，且未耗尽上限时，不计入次数限制。（X为上述角色数-这些角色本轮使用【杀】次数）",
    ["@ysch5_zhoushi-round"] = "舟师",
    ["ysch5_lianhuan"] = "连环",
    [":ysch5_lianhuan"] = "<a href = ':Battlefield'>战场技！</a>出牌阶段，你可以重铸任意张♣牌，视为使用一张目标数相等的【火攻】或【铁锁连环】，并令此牌目标角色进入或离开<a href = ':ysch5_chibi'>〖赤壁〗</a>。",
    ["ysch5_chibi"] = "赤壁",
    ["#ysch5_chibi"] = "赤壁",
    [":ysch5_chibi"] = "转换技，一名角色进入或离开赤壁时转换，①赤壁内的角色始终横置；②赤壁外的角色始终横置；③对赤壁内的角色依次造成1点火焰伤害。",
    ["@[:]ysch5_chibi"] = "战场",
    ["ysch5_chibi1"] = "赤壁①",
    [":ysch5_chibi1"] = "赤壁内的角色始终横置。<br><br><b>下次有人进入或离开时</b>：赤壁外的角色始终横置。",
    ["ysch5_chibi2"] = "赤壁②",
    [":ysch5_chibi2"] = "赤壁外的角色始终横置。<br><br><b>下次有人进入或离开时</b>：对赤壁内的角色依次造成1点火焰伤害。",
    ["ysch5_chibi3"] = "赤壁③",
    [":ysch5_chibi3"] = "对赤壁内的角色依次造成1点火焰伤害。<br><br><b>下次有人进入或离开时</b>：赤壁内的角色始终横置。",
}

local simayiyi = General:new(extension, "ysch5__simayiyi", "PeaceBook", 3, 3, General.Female)--
Fk:loadTranslationTable{
    ["PeaceBook"] = "天书",
    ["ysch5__simayiyi"] = "司马一一",
    ["#ysch5__simayiyi"] = "甜酷靓飒",
    ["designer:ysch5__simayiyi"] = "铝",
    ["cv:ysch5__simayiyi"] = "未知",
    ["illustrator:ysch5__simayiyi"] = "hamiro",
}
local songan = fk.CreateTriggerSkill{
    name = "ysch5_songan",
    events = {fk.GameStart, fk.AskForRetrial, fk.CardUsing, fk.CardResponding, fk.FinishJudge},
    mute = true,
    can_trigger = function (self, event, target, player, data)
        if player:hasSkill(self.name) then
            if event == fk.GameStart then
                return true
            elseif event == fk.AskForRetrial then
                return not player:isNude()
            elseif event == fk.CardUsing or event == fk.CardResponding then
                return target == player and data.card.trueName == "jink" or data.card.trueName == "lightning"
            elseif event == fk.FinishJudge then
                return target == player and data.card.color == Card.Black
            end
        end
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        if event == fk.GameStart then
            local choice = room:askForChoice(player,{"ol_ex__leiji","ex__guicai"},self.name,"#ysch5_songan-invoke",true)
            self.cost_data = choice
            return true
        elseif event == fk.AskForRetrial then
            local choices = {}
            for _, value in ipairs({"ol_ex__leiji","ex__guicai"}) do
                local mark = player:getTableMark("ysch5_songan-round")
                if #table.filter(mark,function (v)
                    return v == value
                end) < 1 and
                (type(player:getMark("@[private]ysch5_songan")) ~= "table" or not player:getMark("@[private]ysch5_songan").value or not table.contains(player:getMark("@[private]ysch5_songan").value, value)) then
                    table.insertIfNeed(choices,value)
                end
            end
            if #choices > 0 then
                table.insert(choices,"Cancel")
                local choice = room:askForChoice(player,choices,self.name,"#ysch5_songan-prompt:::".."ex__guicai")
                if choice ~= "Cancel" then
                    room:addTableMark(player,"ysch5_songan-round",choice)
                    U.setPrivateMark(player, "ysch5_songan", {choice})
                end
            end
            if type(player:getMark("@[private]ysch5_songan")) == "table" and player:getMark("@[private]ysch5_songan").value and table.contains(player:getMark("@[private]ysch5_songan").value, "ex__guicai") then
                local card = room:askForCard(player, 1, 1, true, self.name, true, ".|.|.|hand,equip",
                "#ex__guicai-ask::" .. target.id .. ":" .. data.reason)
                if #card > 0 then
                    room:doIndicate(player.id, {target.id})
                    self.cost_data = card[1]
                    return true
                end
            end
        else
            local choices = {}
            for _, value in ipairs({"ol_ex__leiji","ex__guicai"}) do
                local mark = player:getTableMark("ysch5_songan-round")
                if #table.filter(mark,function (v)
                    return v == value
                end) < 1 and
                (type(player:getMark("@[private]ysch5_songan")) ~= "table" or not player:getMark("@[private]ysch5_songan").value or not table.contains(player:getMark("@[private]ysch5_songan").value, value)) then
                    table.insertIfNeed(choices,value)
                end
            end
            if #choices > 0 then
                table.insert(choices,"Cancel")
                local choice = room:askForChoice(player,choices,self.name,"#ysch5_songan-prompt:::".."ol_ex__leiji")
                if choice ~= "Cancel" then
                    room:addTableMark(player,"ysch5_songan-round",choice)
                    U.setPrivateMark(player, "ysch5_songan", {choice})
                end
            end
            if type(player:getMark("@[private]ysch5_songan")) == "table" and player:getMark("@[private]ysch5_songan").value and table.contains(player:getMark("@[private]ysch5_songan").value, "ol_ex__leiji") then
                if event == fk.CardUsing or event == fk.CardResponding then
                    return player.room:askForSkillInvoke(player, self.name, nil, "你想发动〖雷击〗吗？")
                elseif event == fk.FinishJudge then
                    return true
                end
            end
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        if event == fk.GameStart then
            room:notifySkillInvoked(player,self.name,"special")
            U.setPrivateMark(player, "ysch5_songan", {self.cost_data})
        elseif event == fk.AskForRetrial then
            room:notifySkillInvoked(player,self.name,"control")
            room:retrial(Fk:getCardById(self.cost_data), player, data, self.name)
        elseif event == fk.CardUsing or event == fk.CardResponding then
            room:notifySkillInvoked(player,self.name,"offensive")
            local judge = {who = player, reason = self.name,}
            room:judge(judge)
        elseif event == fk.FinishJudge then
            room:notifySkillInvoked(player,self.name,"offensive")
            local x = 2
            if data.card.suit == Card.Club then
            x = 1
            if player:isWounded() then
                room:recover({
                who = player,
                num = 1,
                recoverBy = player,
                skillName = self.name,
                })
            end
            if player.dead then return false end
            end
            local targets = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player, false), Util.IdMapper), 1, 1,
            "#ol_ex__leiji-choose:::" .. x, self.name, true)
            if #targets > 0 then
            local tar = targets[1]
            room:damage{
                from = player,
                to = room:getPlayerById(tar),
                damage = x,
                damageType = fk.ThunderDamage,
                skillName = self.name,
            }
            end
        end
    end,
}
simayiyi:addSkill(songan)
local yizuo = fk.CreateViewAsSkill{
    name = "ysch5_yizuo",
    expand_pile = function (self, player)
        return player.player_cards[Player.Judge]
    end,
    interaction = function (self, player)
        local names = U.getViewAsCardNames(player, self.name, {"jink","lightning"})
        if #names == 0 then return end
        return U.CardNameBox{choices = names, all_choices = {"jink","lightning"}}
    end,
    pattern = "jink,lightning",
    card_filter = function(self, to_select, selected, player)
        if self.interaction.data == nil then return false end
        local card = Fk:getCardById(to_select)
        if self.interaction.data == "jink" then
            return card.trueName == "lightning"
        else
            return card.trueName == "jink"
        end
    end,
    view_as = function (self, cards, player)
        if self.interaction.data == nil or #cards == 0 then return nil end
        local c = Fk:cloneCard(self.interaction.data)
        c.skillName = self.name
        c:addSubcards(cards)
        return c
    end,
    before_use = function (self, player, use)
        player.room:responseCard({from = player.id,card = Fk:getCardById(use.card.subcards[1])})
    end,
    enabled_at_play = function (self, player)
        return player:usedSkillTimes(self.name,Player.HistoryTurn) == 0
    end,
    enabled_at_response = function (self, player, response)
        return not response and player:usedSkillTimes(self.name,Player.HistoryTurn) == 0
    end,
}
simayiyi:addSkill(yizuo)
if not Fk.skills["ol_ex__leiji"] then
    local ol_ex__leiji = fk.CreateTriggerSkill{
        name = "ol_ex__leiji",
        anim_type = "offensive",
        events = {fk.CardUsing, fk.CardResponding, fk.FinishJudge},
        can_trigger = function(self, event, target, player, data)
            if player:hasSkill(self) and target == player then
                if event == fk.CardUsing or event == fk.CardResponding then
                return data.card.trueName == "jink" or data.card.trueName == "lightning"
                elseif event == fk.FinishJudge then
                return data.card.color == Card.Black
                end
            end
        end,
        on_cost = function(self, event, target, player, data)
            if event == fk.CardUsing or event == fk.CardResponding then
                return player.room:askForSkillInvoke(player, self.name)
            elseif event == fk.FinishJudge then
                return true
            end
        end,
        on_use = function(self, event, target, player, data)
            local room = player.room
            if event == fk.CardUsing or event == fk.CardResponding then
                local judge = {
                who = player,
                reason = self.name,
                }
                room:judge(judge)
            elseif event == fk.FinishJudge then
                local x = 2
                if data.card.suit == Card.Club then
                x = 1
                if player:isWounded() then
                    room:recover({
                    who = player,
                    num = 1,
                    recoverBy = player,
                    skillName = self.name,
                    })
                end
                if player.dead then return false end
                end
                local targets = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player, false), Util.IdMapper), 1, 1,
                "#ol_ex__leiji-choose:::" .. x, self.name, true)
                if #targets > 0 then
                local tar = targets[1]
                room:damage{
                    from = player,
                    to = room:getPlayerById(tar),
                    damage = x,
                    damageType = fk.ThunderDamage,
                    skillName = self.name,
                }
                end
            end
        end,
    }
    Fk:addSkill(ol_ex__leiji)
    Fk:loadTranslationTable{
        ["ol_ex__leiji"] = "雷击",
        [":ol_ex__leiji"] = "当你使用或打出【闪】或【闪电】时，你可以进行判定。当你的判定结果确定后，若结果为：♠，你可以对一名其他角色造成2点雷电伤害；"..
        "♣，你回复1点体力，然后你可以对一名其他角色造成1点雷电伤害。",
    }
end
if not Fk.skills["ex__guicai"] then
    local ex__guicai = fk.CreateTriggerSkill{
        name = "ex__guicai",
        anim_type = "control",
        events = {fk.AskForRetrial},
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(self) and not player:isNude()
        end,
        on_cost = function(self, event, target, player, data)
            local room = player.room
            local card = room:askForCard(player, 1, 1, true, self.name, true, ".|.|.|hand,equip",
            "#ex__guicai-ask::" .. target.id .. ":" .. data.reason)
            if #card > 0 then
                room:doIndicate(player.id, {target.id})
                self.cost_data = card[1]
                return true
            end
        end,
        on_use = function(self, event, target, player, data)
            player.room:retrial(Fk:getCardById(self.cost_data), player, data, self.name)
        end,
    }
    Fk:addSkill(ex__guicai)
    Fk:loadTranslationTable{
        ["ex__guicai"] = "鬼才",
        [":ex__guicai"] = "当判定结果确定前，你可打出一张牌代替之。",
        ["#ex__guicai-ask"] = "是否发动 鬼才，打出一张牌代替 %dest 的 %arg 判定",
    }
end
simayiyi:addRelatedSkill("ol_ex__leiji")
simayiyi:addRelatedSkill("ex__guicai")
Fk:loadTranslationTable{
    ["ysch5_songan"] = "颂安",
    [":ysch5_songan"] = "游戏开始时，你秘密获得“<a href = ':ol_ex__leiji'>雷击</a>”或“<a href = ':ex__guicai'>鬼才</a>”中的一个。每轮各限一次，你需要发动其中一项时，可以秘密切换至其中一项。",
    ["#ysch5_songan-invoke"] = "颂安：选择一个技能获得",
    ["#ysch5_songan-prompt"] = "颂安：当前可以发动“%arg”，是否秘密切换至其中一项？",
    ["@[private]ysch5_songan"] = "颂安",
    ["ysch5_yizuo"] = "懿佐",
    [":ysch5_yizuo"] = "每回合限一次，你可以打出区域内的一张【闪】或【闪电】以当另一项使用。",
}

local guoxiaoye = General:new(extension, "ysch5__guoxiaoye", "PeaceBook", 3, 3, General.Male)--
Fk:loadTranslationTable{
    ["ysch5__guoxiaoye"] = "郭小野",
    ["#ysch5__guoxiaoye"] = "",
    ["designer:ysch5__guoxiaoye"] = "胖即是胖",
    ["cv:ysch5__guoxiaoye"] = "未知",
    ["illustrator:ysch5__guoxiaoye"] = "",
}
local lengfeng = fk.CreateActiveSkill{
    name = "ysch5_lengfeng",
    min_target_num = 1,
    target_filter = function(self, to_select, selected)
        return #selected < 2
    end,
    card_num = 0,
    card_filter = Util.FalseFunc,
    can_use = function (self, player, card, extra_data)
        return player:usedSkillTimes(self.name,Player.HistoryPhase) == 0
    end,
    target_tip = function (self, to_select, selected, selected_cards, card, selectable, extra_data)
        if #selected > 0 then
            if #selected == 1 then
                if table.contains(selected,to_select) then
                    return "#ysch5_lengfeng0"
                end
            else
                if selected[1] == to_select then
                    return "#ysch5_lengfeng1"
                else
                    return "#ysch5_lengfeng2"
                end
            end
        end
    end,
    on_use = function (self, room, effect)
        local player = room:getPlayerById(effect.from)
        local to1 = room:getPlayerById(effect.tos[1])
        local to2 = room:getPlayerById(effect.tos[#effect.tos])
        room:damage({from = player, to = to1, damage = 1, damageType = fk.IceDamage, skillName = self.name})
        room:recover({who = to2, num = 1, skillName = self.name, recoverBy = player})
        if to1.id ~= to2.id then
            room:handleAddLoseSkills(player,"-"..self.name)
        elseif to1.id == player.id then
            room:changeMaxHp(player, 1)
        end
    end,
}
guoxiaoye:addSkill(lengfeng)
local jiayi = fk.CreateTriggerSkill{
    name = "ysch5_jiayi",
    anim_type = "masochism",
    events = {fk.Damaged},
    on_trigger = function(self, event, target, player, data)
        self.cancel_cost = false
        for _ = 1, data.damage do
            if self.cancel_cost or not player:hasSkill(self) then break end
            self:doCost(event, target, player, data)
        end
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        if room:askForSkillInvoke(player, self.name, data) then
            return true
        end
        self.cancel_cost = true
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local cards = table.filter(room.draw_pile, function (id)
            return Fk:getCardById(id).type == Card.TypeTrick
        end)
        table.insertTable(cards, table.filter(room.void, function (id)
            return Fk:getCardById(id):getMark(self.name) ~= 0 and Fk:getCardById(id).type == Card.TypeTrick
        end))
        local extraInfo = room:getTag("ysch5_jiayi_cards")
        if extraInfo == nil or (type(extraInfo)=="table" and #extraInfo == 0) then
            extraInfo = {}
            local ban_packageName = {"3v3_cards","1v1_cards","aaa_steam_sanshe_derived","tangz_ld_cards"}
            local ban_cardName = {"premeditate"}
            for name, card in pairs(Fk.all_card_types) do
                if card.type == Card.TypeTrick and table.contains(Fk:currentRoom().disabled_packs, card.package.name) then
                    if not table.contains(ban_packageName, card.package.name) and not table.contains(ban_cardName, card.trueName) then
                        table.insert(extraInfo, {name, card.suit < 5 and card.suit or math.random(4),card.number > 0 and card.number or math.random(13)})
                    end
                end
            end
        end
        local shows = {}
        for i = 1, player.maxHp, 1 do
            if #cards == 0 or math.random() < 0.4 then
                if #extraInfo > 0 then
                    local info = table.random(extraInfo)
                    table.removeOne(extraInfo, info)
                    local card = room:printCard(info[1], info[2], info[3])
                    room:setCardMark(card, MarkEnum.DestructIntoDiscard, 1)
                    room:setCardMark(card, self.name, 1)
                    table.insert(shows, card.id)
                end
            else
                table.insert(shows, table.remove(cards, math.random(#cards)))
            end
        end
        room:setTag("ysch5_jiayi_cards", extraInfo)
        room:showCards(shows, player)
        local get = room:askForCardsChosen(player, player, 1, 2, { card_data = { { self.name, shows } } }, self.name, "#ysch5_jiayi-card")
        room:obtainCard(player, get, false, fk.ReasonJustMove, player.id, self.name)
    end,
}
guoxiaoye:addSkill(jiayi)
Fk:loadTranslationTable{
    ["ysch5_lengfeng"] = "冷锋",
    [":ysch5_lengfeng"] = "出牌阶段限一次，你可以对一名角色造成1点冰冻伤害，然后你令一名角色回复1点体力；若这两名角色：不为同一名角色，你失去此技能；为你，你加1点体力上限。",
    ["#ysch5_lengfeng0"] = "冰伤和回血",
    ["#ysch5_lengfeng1"] = "冰伤",
    ["#ysch5_lengfeng2"] = "回血",
    ["ysch5_jiayi"] = "嘉翼",
    [":ysch5_jiayi"] = "当你受到1点伤害后，你可以随机展示牌堆和游戏外共计X张锦囊牌（X为你的体力上限），然后你获得其中至多两张牌。",
    ["#ysch5_jiayi-card"] = "嘉翼：获得其中两张牌",
}
local baiqi = General:new(extension, "ysch5__baiqi", "qin", 5, 5, General.Male)--
Fk:loadTranslationTable{
    ["qin"] = "秦",
    ["ysch5__baiqi"] = "白起",
    ["#ysch5__baiqi"] = "血战长平",
    ["designer:ysch5__baiqi"] = "铝",
    ["cv:ysch5__baiqi"] = "未知",
    ["illustrator:ysch5__baiqi"] = "",
}
local juefa = fk.CreateTriggerSkill{
    name = "ysch5_juefa",
    events = {fk.CardUsing},
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(self.name) and target == player
    end,
    anim_type = "offensive",
    on_cost = Util.TrueFunc,
    on_use = function (self, event, target, player, data)
        player.room:addPlayerMark(player,"@!ysch5_juefa")
    end,

    refresh_events = {fk.RoundStart,fk.DrawNCards},
    can_refresh = function (self, event, target, player, data)
        if event == fk.RoundStart then
            return player:getMark("@!ysch5_juefa") > 0
        else
            return target == player and player:getMark("@ysch5_juefa-round") > 0
        end
    end,
    on_refresh = function (self, event, target, player, data)
        if event == fk.RoundStart then
            local room = player.room
            room:setPlayerMark(player,"@ysch5_juefa-round",player:getMark("@!ysch5_juefa"))
            room:setPlayerMark(player,"@!ysch5_juefa",0)
        else
            data.n = data.n + player:getMark("@ysch5_juefa-round")
        end
    end,
}
local juefa_targetmod = fk.CreateTargetModSkill{
    name = "#ysch5_juefa_targetmod",
    main_skill = juefa,
    residue_func = function(self, player, skill, scope)
        if player:getMark("@ysch5_juefa-round") > 0 and skill.trueName == "slash_skill" and scope == Player.HistoryPhase then
            return player:getMark("@ysch5_juefa-round")
        end
    end,
}
juefa:addRelatedSkill(juefa_targetmod)
baiqi:addSkill(juefa)
Fk:loadTranslationTable{
    ["ysch5_juefa"] = "绝伐",
    [":ysch5_juefa"] = "你使用牌时，下轮摸牌阶段摸牌数和出【杀】次数+1。",
    ["@!ysch5_juefa"] = "绝伐",
    ["@ysch5_juefa-round"] = "绝伐",

    ["$ysch5_juefa1"] = "受封武安，为国尽忠！",
    ["$ysch5_juefa2"] = "战场，是我的舞台！",
    ["$ysch5_juefa3"] = "兴兵伐楚，稳大秦基业！",
    ["$ysch5_juefa4"] = "百战百胜，攻无不克！",
    ["~ysch5__baiqi"] = "将士迟暮，难以再战……",
}
local mengtian = General:new(extension, "ysch5__mengtian", "qin", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch5__mengtian"] = "蒙恬",
    ["#ysch5__mengtian"] = "秩序统将",
    ["designer:ysch5__mengtian"] = "铝",
    ["cv:ysch5__mengtian"] = "未知",
    ["illustrator:ysch5__mengtian"] = "",
}
local zhubei = fk.CreateTriggerSkill{
    name = "ysch5_zhubei",
    events = {fk.EventPhaseEnd},
    anim_type = "defensive",
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(self) and player.phase == Player.Play
    end,
    on_cost = function (self, event, target, player, data)
        if player.room:askForSkillInvoke(player,self.name,nil,"#ysch5_zhubei-invoke") then
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local i = 0
        while i < 4 do
            local use = U.askForPlayCard(player.room, player, nil, nil, self.name, "#ysch5_zhubei-use:::"..i, {bypass_times = true}, true)
            if use then
                use.extraUse = true
                room:useCard(use)
                i = i + 1
            else
                local ids = room:askForDiscard(player,1,4-i,true,self.name,false,".","#ysch5_zhubei-discard:::"..(4-i)..":"..i,false)
                if #ids > 0 then
                    i = i + #ids
                else
                    break
                end
            end
        end
        if i >= 4 then
            local choice = room:askForChoice(player,{"#ysch5_zhubei1","#ysch5_zhubei2","#ysch5_zhubei3"},self.name,"#ysch5_zhubei-choose")
            if choice == "#ysch5_zhubei1" then
                room:addPlayerMark(player,"@ysch5_zhubei1-round",3)
                room:changeMaxHp(player,3)
                room:recover({
                    who = player,
                    num = 3,
                    recoverBy = player,
                    skillName = self.name
                })
            elseif choice == "#ysch5_zhubei2" then
                room:addPlayerMark(player,"@ysch5_zhubei2-round",2)
                room:drawCards(player,2,self.name)
            else
                room:setPlayerMark(player,"@ysch5_zhubei3-round",1)
                local tos = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1, "#ysch5_zhubei-damage", self.name, false)
                if #tos > 0 then
                    room:damage { from = player, to = room:getPlayerById(tos[1]), damage = 1, skillName = self.name }
                end
            end
        end
    end,

    refresh_events = {fk.RoundEnd,fk.DamageInflicted},
    can_refresh = function (self, event, target, player, data)
        if event == fk.RoundEnd then
            return player:getMark("@ysch5_zhubei1-round") > 0
        else
            local num = 0
            player.room.logic:getActualDamageEvents(1, function(e)
                if e.data[1].to == player then
                    num = num + e.data[1].damage
                end
                return false
            end, Player.HistoryRound)
            return num >= 1 and player:getMark("@ysch5_zhubei3-round") > 0 and target == player
        end
    end,
    on_refresh = function (self, event, target, player, data)
        if event == fk.RoundEnd then
            player.room:changeMaxHp(player,-player:getMark("@ysch5_zhubei1-round"))
        else
            data.damage = 0
        end
    end,
}
local zhubei_maxCards = fk.CreateMaxCardsSkill{
    name = "#ysch5_zhubei_maxcards",
    correct_func = function(self, player)
        return player:getMark("@ysch5_zhubei2-round")
    end,
}
zhubei:addRelatedSkill(zhubei_maxCards)
mengtian:addSkill(zhubei)
Fk:loadTranslationTable{
    ["ysch5_zhubei"] = "筑北",
    [":ysch5_zhubei"] = "出牌阶段结束时，你可以依次使用或弃置四张牌，然后选择一项：本轮体力上限+3，回复3点体力；本轮手牌上限+2，摸两张牌；本轮至多受到1点伤害，分配1点伤害。",
    ["#ysch5_zhubei-invoke"] = "是否发动 筑北，依次使用或弃置四张牌",
    ["#ysch5_zhubei-use"] = "筑北：使用四张牌（%arg/4）",
    ["#ysch5_zhubei-discard"] = "筑北：弃置至多%arg张牌（%arg2/4）",
    ["#ysch5_zhubei-choose"] = "筑北：选择一项",
    ["#ysch5_zhubei1"] = "本轮体力上限+3，回复3点体力",
    ["#ysch5_zhubei2"] = "本轮手牌上限+2，摸两张牌",
    ["#ysch5_zhubei3"] = "本轮至多受到1点伤害，分配1点伤害",
    ["#ysch5_zhubei-damage"] = "筑北：分配1点伤害",
    ["@ysch5_zhubei1-round"] = "体力上限+",
    ["@ysch5_zhubei2-round"] = "手牌上限+",
    ["@ysch5_zhubei3-round"] = "受伤上限=",
}
local xiangyu = General:new(extension, "ysch5__xiangyu", "chu", 5, 5, General.Male)--
Fk:loadTranslationTable{
    ["ysch5__xiangyu"] = "项羽",
    ["#ysch5__xiangyu"] = "优柔寡断",
    ["designer:ysch5__xiangyu"] = "铝&独孤妙妙",
    ["cv:ysch5__xiangyu"] = "未知",
    ["illustrator:ysch5__xiangyu"] = "",
}
local bawang = fk.CreateViewAsSkill{
    name = "ysch5_bawang",
    anim_type = "offensive",
    pattern = ".",
    interaction = function (self, player)
        local names, all_names = {}, {}
        for _, id in ipairs(Fk:getAllCardIds()) do
            local card = Fk:getCardById(id)
            if card.type == Card.TypeBasic or card.type == Card.TypeTrick then
                if #table.filter(player:getCardIds("h"),function (cardId)
                    return Fk:getCardById(cardId):getMark("@@ysch5_bawang_"..card.name.."-inhand") > 0
                end) > 0 then
                    table.insertIfNeed(all_names, card.name)
                    local to_use = Fk:cloneCard(card.name)
                    if ((Fk.currentResponsePattern == nil and Self:canUse(to_use) and not Self:prohibitUse(to_use)) or
                    (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(to_use))) then
                        table.insertIfNeed(names, card.name)
                    end
                end
            end
        end
        if #names == 0 then return false end
        return U.CardNameBox { choices = names, all_choices = all_names }
    end,
    card_filter = function(self, to_select, selected)
        if not self.interaction.data then return end
        local card = Fk:getCardById(to_select)
        return #selected == 0 and card:getMark("@@ysch5_bawang_"..self.interaction.data.."-inhand") > 0
    end,
    view_as = function(self, cards)
        if #cards ~= 1 or not self.interaction.data then return end
        local card = Fk:cloneCard(self.interaction.data)
        card:addSubcards(cards)
        card.skillName = self.name
        return card
    end,
    enabled_at_play = function(self, player)
        return not player:isNude()
    end,
    enabled_at_response = function(self, player, response)
        return not response and not player:isNude()
    end,
}
local bawang_trigger = fk.CreateTriggerSkill{
    name = "#ysch5_bawang_trigger",
    events = {fk.AfterCardsMove,fk.CardUseFinished},
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(bawang.name) then
            if event == fk.AfterCardsMove then
                for _, move in ipairs(data) do
                    if move.from == player.id then
                        for _, info in ipairs(move.moveInfo) do
                            if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
                                return true
                            end
                        end
                    end
                end
            else
                return (data.extra_data and data.extra_data.ysch5_bawang) or data.card.skillName == "ysch5_bawang"
            end
        end
    end,
    on_cost = function (self, event, target, player, data)
        if event == fk.CardUseFinished then
            if data.damageDealt ~= nil then return true end
            local cards = player.room:askForCard(player, 1, 1, true, self.name, false, ".", "#ysch5_bawang-recast")
            self.cost_data = cards
        end
        return true
    end,
    mute = true,
    on_use = function(self, event, target, player, data)
        local room = player.room
        room:notifySkillInvoked(player,"ysch5_bawang","offensive")
        if event == fk.AfterCardsMove then
            for _, move in ipairs(data) do
                if move.from == player.id then
                    for _, info in ipairs(move.moveInfo) do
                        if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
                            local name = Fk:getCardById(info.cardId).name
                            local cards = table.filter(player:getCardIds("h"),function (id)
                                return Fk:getCardById(id):getMark("@@ysch5_bawang_"..name.."-inhand") == 0
                            end)
                            if #cards > 0 then
                                room:setCardMark(Fk:getCardById(table.random(cards)),"@@ysch5_bawang_"..name.."-inhand",1)
                            end
                        end
                    end
                end
            end
        else
            if data.damageDealt then
                player:drawCards(1,"ysch5_bawang")
            else
                room:recastCard(self.cost_data, player, "ysch5_bawang")
            end
        end
    end,

    refresh_events = {fk.PreCardUse},
    can_refresh = function (self, event, target, player, data)
        if target == player then
            for k, _ in pairs(data.card.mark) do
                if string.find(k,"@@ysch5_bawang_") then
                    return true
                end
            end
        end
    end,
    on_refresh = function (self, event, target, player, data)
        data.extra_data = data.extra_data or {}
        data.extra_data.ysch5_bawang = true
    end,
}
bawang:addRelatedSkill(bawang_trigger)
xiangyu:addSkill(bawang)
Fk:loadTranslationTable{
    ["ysch5_bawang"] = "霸王",
    [":ysch5_bawang"] = "当你失去一张牌后，令手牌中随机一张牌可以当此牌使用。此牌结算后，你重铸一张牌，若造成了伤害，则改为摸牌。",
    ["#ysch5_bawang-recast"] = "霸王：重铸一张牌",
}
local hanxin = General:new(extension, "ysch5__hanxin", "han", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch5__hanxin"] = "韩信",
    ["#ysch5__hanxin"] = "国士无双",
    ["designer:ysch5__hanxin"] = "隐匿",
    ["cv:ysch5__hanxin"] = "未知",
    ["illustrator:ysch5__hanxin"] = "",
}
local dianbing = fk.CreateActiveSkill{
    name = "ysch5_dianbing",
    times = function(self)
        return Self.phase == Player.Play and 3 - Self:usedSkillTimes(self.name, Player.HistoryPhase) or -1
    end,
    can_use = function (self, player)
        return player:usedSkillTimes(self.name, Player.HistoryPhase) < 3
    end,
    card_filter = function(self, to_select, selected)
        return #selected == 0 and Fk:getCardById(to_select):getMark("@@ShownCards-inhand") == 0 and table.contains(Self.player_cards[Player.Hand], to_select)
    end,
    card_num = 1,
    target_num = 0,
    target_filter = Util.FalseFunc,
    prompt = "#ysch5_dianbing",
    on_use = function (self, room, effect)
        local card = Fk:getCardById(effect.cards[1])
        local player = room:getPlayerById(effect.from)
        room:setCardMark(card, "@@ShownCards-inhand", 1)
        if not player.dead then
            if card.trueName == "slash" then
                U.askForUseVirtualCard(room, player, card.name, nil, self.name, "#ysch5_dianbing-slash:::"..card:toLogString(), false, true, false, true)
                player:drawCards(1, "recast")
            else
                if not U.askForUseVirtualCard(room, player, card.name, nil, self.name, "#ysch5_dianbing-use:::"..card:toLogString(), true, true, false, true) then
                    player:drawCards(1, "recast")
                end
            end
        end
    end,
}
hanxin:addSkill(dianbing)
Fk:loadTranslationTable{
    ["ysch5_dianbing"] = "点兵",
    [":ysch5_dianbing"] = "出牌阶段限三次，你可以明置一张手牌，然后视为使用或重铸这张牌。若为【杀】，则均执行。",
    ["#ysch5_dianbing"] = "是否发动 点兵，明置一张手牌",
    ["#ysch5_dianbing-use"] = "点兵：视为使用%arg，或点“取消”视为重铸此牌",
    ["#ysch5_dianbing-slash"] = "点兵：视为使用%arg",
}
local lvzhi = General:new(extension, "ysch5__lvzhi", "han", 4, 4, General.Female)--
Fk:loadTranslationTable{
    ["ysch5__lvzhi"] = "吕雉",
    ["#ysch5__lvzhi"] = "霸业的暗裁者",
    ["designer:ysch5__lvzhi"] = "隐匿",
    ["cv:ysch5__lvzhi"] = "未知",
    ["illustrator:ysch5__lvzhi"] = "代号杀",
}
local jianyi = fk.CreateActiveSkill{
    name = "ysch5_jianyi",
    anim_type = "special",
    interaction = function(self)
        return UI.ComboBox {choices = {"ysch5_yuce","ysch5_zhendu"}}
    end,
    card_num = 1,
    can_use = function (self, player)
        return player:usedSkillTimes(self.name, Player.HistoryPhase) < 1
    end,
    card_filter = function (self, to_select, selected, player)
        return #selected == 0 and table.contains(Self.player_cards[Player.Hand], to_select)
    end,
    target_num = 0,
    target_filter = Util.FalseFunc,
    on_use = function (self, room, effect)
        local player = room:getPlayerById(effect.from)
        if self.interaction.data == "ysch5_yuce" then
            room:notifySkillInvoked(player,"ysch5_yuce","defensive")
            player:showCards({effect.cards[1]})
            room:recover{
                who = player,
                num = 1,
                recoverBy = player,
                skillName = self.name
            }
            if Fk:getCardById(effect.cards[1]).color == Card.Black then
                room:setPlayerMark(player,"@[desc]ysch5_zizouqi_zhendu",1)
            end
        else
            room:notifySkillInvoked(player,"ysch5_zhendu","offensive")
            room:throwCard(effect.cards, self.name, player, player)
            if not player.dead then
                room:useVirtualCard("analeptic", nil, player, player, self.name, false)
            end
            if Fk:getCardById(effect.cards[1]).color == Card.Red then
                room:setPlayerMark(player,"@[desc]ysch5_zizouqi_yuce",1)
            end
        end
    end,
}
lvzhi:addSkill(jianyi)
local yuce = fk.CreateTriggerSkill{
    name = "ysch5_yuce",
    anim_type = "defensive",
    events = {fk.Damaged},
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(self) and not player:isKongcheng()
    end,
    on_cost = function(self, event, target, player, data)
        local card = player.room:askForCard(player, 1, 1, false, self.name, true, ".", "#yuce-invoke")
        if #card > 0 then
            self.cost_data = card[1]
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local c = self.cost_data
        player:showCards({c})
        if player.dead then return end
        if not data.from or data.from.dead or data.from:isKongcheng() then
        room:recover{
            who = player,
            num = 1,
            recoverBy = player,
            skillName = self.name
        }
        else
        local types = {"basic", "trick", "equip"}
        table.removeOne(types, Fk:getCardById(c):getTypeString())
        if #room:askForDiscard(data.from, 1, 1, false, self.name, true, ".|.|.|hand|.|"..table.concat(types, ","),
            "#yuce-discard:"..player.id..":"..Fk:getCardById(c):getTypeString()) == 0 then
            room:recover{
            who = player,
            num = 1,
            recoverBy = player,
            skillName = self.name
            }
        end
        end
    end,
}
lvzhi:addRelatedSkill(yuce)
local ol__zhendu = fk.CreateTriggerSkill{
    name = "ysch5_zhendu",
    anim_type = "offensive",
    events = {fk.EventPhaseStart},
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(self) and target.phase == Player.Play and not player:isKongcheng() and not target.dead
    end,
    on_cost = function(self, event, target, player, data)
        local prompt = (target == player) and "#ol__zhendu-self" or "#ol__zhendu-invoke::"..target.id
        local card = player.room:askForDiscard(player, 1, 1, false, self.name, true, ".", prompt, true)
        if #card > 0 then
        player.room:doIndicate(player.id, {target.id})
        self.cost_data = {tos = {target.id}, cards = card}
        return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        room:throwCard(self.cost_data.cards, self.name, player, player)
        if not target.dead and target:canUseTo(Fk:cloneCard("analeptic"), target) then
        room:useVirtualCard("analeptic", nil, target, target, self.name, false)
        end
        if player ~= target and not target.dead then
        room:damage{
            from = player,
            to = target,
            damage = 1,
            skillName = self.name,
        }
        end
    end,
}
lvzhi:addRelatedSkill(ol__zhendu)
local zizouqi_yuce = fk.CreateTriggerSkill{
    name = "#ysch5_zizouqi_yuce",
    events = {fk.DamageInflicted},
    can_trigger = function(self, event, target, player, data)
        return target == player and player:getMark("@[desc]ysch5_zizouqi_yuce") ~= 0
    end,
    priority = 0.1,
    global = true,
    mute = true,
    on_cost = Util.TrueFunc,
    on_use = function (self, event, target, player, data)
        player.room:setPlayerMark(player,"@[desc]ysch5_zizouqi_yuce",0)
        return true
    end,
}
Fk:addSkill(zizouqi_yuce)
local zizouqi_zhendu = fk.CreateTriggerSkill{
    name = "#ysch5_zizouqi_zhendu",
    events = {fk.Damage},
    can_trigger = function(self, event, target, player, data)
        return target == player and player:getMark("@[desc]ysch5_zizouqi_zhendu") ~= 0 and data.to:isAlive()
    end,
    priority = 0.1,
    global = true,
    mute = true,
    on_cost = Util.TrueFunc,
    on_use = function (self, event, target, player, data)
        player.room:setPlayerMark(player,"@[desc]ysch5_zizouqi_zhendu",0)
        player.room:killPlayer({who = data.to.id})
    end,
}
Fk:addSkill(zizouqi_zhendu)
Fk:loadTranslationTable{
    ["ysch5_jianyi"] = "翦异",
    [":ysch5_jianyi"] = "出牌阶段限一次，你可以展示一张手牌以发动“御策”/弃置一张手牌以发动“鸩毒”，若你因此展示黑色牌或弃置红色牌，你获得另一项。",

    ["ysch5_yuce"] = "御策",
    [":ysch5_yuce"] = "每当你受到一次伤害后，你可以展示一张手牌，令伤害来源弃置一张类别不同的手牌，否则你回复1点体力。",
    ["#yuce-invoke"] = "御策：你可以展示一张手牌，伤害来源需弃置一张类别不同的手牌，否则你回复1点体力",
    ["#yuce-discard"] = "御策：你需弃置一张非%arg手牌，否则 %src 回复1点体力",
    ["ysch5_zhendu"] = "鸩毒",
    [":ysch5_zhendu"] = "一名角色的出牌阶段开始时，你可以弃置一张手牌。若如此做，该角色视为使用一张【酒】，然后若该角色不为你，你对其造成1点伤害。",
    ["#ol__zhendu-invoke"] = "鸩毒：你可以弃置一张手牌视为 %dest 使用一张【酒】，然后你对其造成1点伤害",
    ["#ol__zhendu-self"] = "鸩毒：你可以弃置一张手牌视为使用一张【酒】",

    ["@[desc]ysch5_zizouqi_yuce"] = "<font color='#e1e100'>御策</font>",
    ["@[desc]ysch5_zizouqi_zhendu"] = "<font color='#b766ad'>鸩毒</font>",
    [":ysch5_zizouqi_yuce"] = "抵挡1次伤害",
    [":ysch5_zizouqi_zhendu"] = "下次对武将造成伤害后，直接击败该武将",
}
local liubang = General:new(extension, "ysch5__liubang", "han", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch5__liubang"] = "刘邦",
    ["#ysch5__liubang"] = "赤霄承命",
    ["designer:ysch5__liubang"] = "铝",
    ["cv:ysch5__liubang"] = "未知",
    ["illustrator:ysch5__liubang"] = "",
}
local xianyu = fk.CreateTriggerSkill{
    name = "ysch4_xianyu",
    events = {fk.AfterCardsMove},
    anim_type = "drawcard",
    frequency = Skill.Compulsory,
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(self) then
            local suits = {}
            for _, move in ipairs(data) do
                if move.toArea == Card.PlayerHand and move.to == player.id then
                    for _, info in ipairs(move.moveInfo) do
                        local card = Fk:getCardById(info.cardId)
                        table.insertIfNeed(suits, card.suit)
                        if #suits > 1 then
                            break
                        end
                    end
                end
            end
            if #suits == 1 then
                self.cost_data = suits[1]
                return true
            end
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local cards = player.player_cards[Player.Hand]
        player:showCards(cards)
        room:drawCards(player, #table.filter(cards,function (id)
            return Fk:getCardById(id).suit == self.cost_data
        end), self.name)
    end,
}
liubang:addSkill(xianyu)
local zhanshe = fk.CreateTriggerSkill{
    name = "ysch4_zhanshe",
    anim_type = "control",
    events = {fk.Damage, fk.Damaged},
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(self) then
            return player:inMyAttackRange(target)
        end
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local targets = {}
        for _, cp in ipairs(room.alive_players) do
            local skills = Fk.generals[cp.general]:getSkillNameList(true)
            if cp.deputyGeneral ~= "" then
                table.insertTableIfNeed(skills, Fk.generals[cp.deputyGeneral]:getSkillNameList(true))
            end
            skills = table.filter(skills, function(s) return cp:hasSkill(s, true) end)
            if #skills > 0 then
                table.insertIfNeed(targets,cp.id)
            end
        end
        if #targets == 0 then return false end
        local to = room:askForChoosePlayers(player, targets, 1, 1, "#ysch4_zhanshe-choose", self.name, true)
        if #to > 0 then
            self.cost_data = to[1]
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local tp = room:getPlayerById(self.cost_data)
        local skills = Fk.generals[tp.general]:getSkillNameList(true)
        if tp.deputyGeneral ~= "" then
            table.insertTableIfNeed(skills, Fk.generals[tp.deputyGeneral]:getSkillNameList(true))
        end
        skills = table.slice(table.filter(skills, function(s) return tp:hasSkill(s, true) end),1,2)
        local mark = tp:getTableMark("ysch4_zhanshe")
        table.insertTable(mark, skills)
        player.room:setPlayerMark(tp, "ysch4_zhanshe", mark)
        tp:drawCards(1,self.name)
        player.room:handleAddLoseSkills(tp, "-"..table.concat(skills, "|-"), nil, true, false)
    end,

    refresh_events = {fk.TurnEnd},
    can_refresh = function(self, event, target, player, data)
        for _, cp in ipairs(player.room.alive_players) do
            if cp:getMark("ysch4_zhanshe") ~= 0 then
                return true
            end
        end
    end,
    on_refresh = function(self, event, target, player, data)
        local room = player.room
        for _, cp in ipairs(player.room.alive_players) do
            if cp:getMark("ysch4_zhanshe") ~= 0 then
                local skills = cp:getTableMark("ysch4_zhanshe")
                room:setPlayerMark(cp, "ysch4_zhanshe", 0)
                room:handleAddLoseSkills(cp, table.concat(skills, "|"), nil, true, false)
            end
        end
    end,
}
liubang:addSkill(zhanshe)
Fk:loadTranslationTable{
    ["ysch4_xianyu"] = "贤驭",
    [":ysch4_xianyu"] = "锁定技，你获得仅一种花色牌时，展示手牌，并摸等同手牌中同花色牌数张牌。",
    ["ysch4_zhanshe"] = "斩蛇",
    [":ysch4_zhanshe"] = "你攻击范围内的角色造成或受到伤害后，你可以令一名角色摸一张牌并失去其首个技能直至回合结束。",
    ["#ysch4_zhanshe-choose"] = "是否发动 斩蛇，令一名角色摸一张牌并失去其首个技能直至回合结束",
}
local weiqing = General:new(extension, "ysch5__weiqing", "han", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch5__weiqing"] = "卫青",
    ["#ysch5__weiqing"] = "瀚海叩勒",
    ["designer:ysch5__weiqing"] = "屑",
    ["cv:ysch5__weiqing"] = "未知",
    ["illustrator:ysch5__weiqing"] = "",
}
local beijin = fk.CreateTriggerSkill{
    name = "ysch5_beijin",
    anim_type = "offensive",
    events = {fk.TurnStart},
    switch_skill_name = "ysch5_beijin",
    dynamic_desc = function (self, player, lang)
        if player:getSwitchSkillState(self.name) == fk.SwitchYang then
            return "转换技，每回合开始时，你可以对一名<font color='#6fb8cc'>阳：有手牌；</font>阴：没手牌的角色造成1点伤害。结算后其可摸两张牌，并转换“北进”，若如此做，你可减1点手牌上限，再转换“北进”。"
        else
            return "转换技，每回合开始时，你可以对一名阳：有手牌；<font color='#6fb8cc'>阴：没手牌</font>的角色造成1点伤害。结算后其可摸两张牌，并转换“北进”，若如此做，你可减1点手牌上限，再转换“北进”。"
        end
    end,
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(self.name)
        and table.find(player.room.alive_players, function (p)
            return (player:getSwitchSkillState(self.name) == fk.SwitchYang and p:getHandcardNum() > 0) or (player:getSwitchSkillState(self.name) == fk.SwitchYin and p:getHandcardNum() == 0)
        end)
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local targets = table.filter(room.alive_players, function (p)
            return (player:getSwitchSkillState(self.name) == fk.SwitchYang and p:getHandcardNum() > 0) or (player:getSwitchSkillState(self.name) == fk.SwitchYin and p:getHandcardNum() == 0)
        end)
        local prompt = "#ysch5_beijin-choose1"
        if player:getSwitchSkillState(self.name) == fk.SwitchYin then prompt = "#ysch5_beijin-choose2" end
        local to = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, prompt, self.name, true)
        if #to > 0 then
            self.cost_data = {tos = to}
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local to = room:getPlayerById(self.cost_data.tos[1])
        room:damage{
            from = player,
            to = to,
            damage = 1,
            skillName = self.name,
        }
        if room:askForSkillInvoke(to,self.name,nil,"#ysch5_beijin-choose3") then
            to:drawCards(2,self.name)
            room:setPlayerMark(player,MarkEnum.SwithSkillPreName .. self.name, player:getSwitchSkillState(self.name,true))
            player:addSkillUseHistory(self.name)
            room:doAnimate("InvokeSkill", {name = self.name,player = player.id,skill_type = "switch",})
            room:sendLog{type = "#ChangeSwitchState",from = to.id,to = {player.id},arg = self.name,arg2 = player:getSwitchSkillState(self.name, false, true),}
            if room:askForSkillInvoke(player,self.name,nil,"#ysch5_beijin-choose4") then
                room:addPlayerMark(player, MarkEnum.MinusMaxCards, 1)
                room:setPlayerMark(player,MarkEnum.SwithSkillPreName .. self.name, player:getSwitchSkillState(self.name,true))
                player:addSkillUseHistory(self.name)
                room:doAnimate("InvokeSkill", {name = self.name,player = player.id,skill_type = "switch",})
                room:sendLog{type = "#ChangeSwitchState",from = player.id,to = {player.id},arg = self.name,arg2 = player:getSwitchSkillState(self.name, false, true),}
            end
        end
    end,
}
weiqing:addSkill(beijin)
Fk:loadTranslationTable{
    ["ysch5_beijin"] = "北进",
    [":ysch5_beijin"] = "转换技，每回合开始时，你可以对一名阳：有手牌；阴：没手牌的角色造成1点伤害。结算后其可摸两张牌，并转换“北进”，若如此做，你可减1点手牌上限，再转换“北进”。",
    ["#ysch5_beijin-choose1"] = "北进：你可以对一名有手牌的角色造成1点伤害",
    ["#ysch5_beijin-choose2"] = "北进：你可以对一名没手牌的角色造成1点伤害",
    ["#ysch5_beijin-choose3"] = "北进：你可以摸两张牌，并转换“北进”",
    ["#ysch5_beijin-choose4"] = "北进：你可以减1点手牌上限，再转换“北进”",
    ["#ChangeSwitchState"] = "%from 将 %to 的转换技 %arg 改变为 %arg2 状态",
}
local huoqubing = General:new(extension, "ysch5__huoqubing", "han", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch5__huoqubing"] = "霍去病",
    ["#ysch5__huoqubing"] = "少年将军",
    ["designer:ysch5__huoqubing"] = "伶",
    ["cv:ysch5__huoqubing"] = "未知",
    ["illustrator:ysch5__huoqubing"] = "",
}
local fufou = fk.CreateTriggerSkill{
    name = "ysch5_fufou",
    events = {fk.TurnStart},
    anim_type = "offensive",
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(self.name) and target == player
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
            local to = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player), Util.IdMapper), 1, 1,
            "#ysch5_fufou-choose", self.name, true)
            if #to > 0 then
                self.cost_data = to[1]
                return true
            end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        room:setPlayerMark(player,"ysch5_fufou-turn",self.cost_data)
        local to = room:getPlayerById(player:getMark("ysch5_fufou-turn"))
        room:setPlayerMark(player,"@ysch5_fufou-turn",to.general)
    end,
}
local fufou_delay = fk.CreateTriggerSkill{
    name = "#ysch5_fufou_delay",
    events = {fk.TurnEnd,fk.CardUsing},
    can_trigger = function (self, event, target, player, data)
        if event == fk.TurnEnd then
            return player:getMark("ysch5_fufou-turn") ~= 0 and not player.room:getPlayerById(player:getMark("ysch5_fufou-turn")).dead and player.room:getPlayerById(player:getMark("ysch5_fufou-turn")):getMark("@ysch5_fufou_draw-turn") > 0
        else
            return player:getMark("ysch5_fufou-turn") ~= 0 and not player.room:getPlayerById(player:getMark("ysch5_fufou-turn")):isNude() and target == player
        end
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        if event == fk.TurnEnd then
            local to = room:getPlayerById(player:getMark("ysch5_fufou-turn"))
            if room:askForSkillInvoke(to,"ysch5_fufou",nil,"#ysch5_fufou-draw::"..player.id..":"..to:getMark("@ysch5_fufou_draw-turn")) then
                return true
            end
        else
            local to = room:getPlayerById(player:getMark("ysch5_fufou-turn"))
            local ids = room:askForCardsChosen(player, to, 0, 1, "he", "ysch5_fufou", "#ysch5_fufou-discard::"..to.id)
            if #ids > 0 then
                self.cost_data = ids
                return true
            end
        end
    end,
    mute = true,
    on_use = function (self, event, target, player, data)
        local room = player.room
        if event == fk.TurnEnd then
            room:notifySkillInvoked(player,"ysch5_fufou","drawcard")
            local to = room:getPlayerById(player:getMark("ysch5_fufou-turn"))
            local num = to:getMark("@ysch5_fufou_draw-turn")
            to:drawCards(num,"ysch5_fufou")
            player:drawCards(num,"ysch5_fufou")
        else
            room:notifySkillInvoked(player,"ysch5_fufou","control")
            local to = room:getPlayerById(player:getMark("ysch5_fufou-turn"))
            room:addPlayerMark(to,"@ysch5_fufou_draw-turn",1)
            room:throwCard(self.cost_data,"ysch5_fufou",to,player)
        end
    end,
}
fufou:addRelatedSkill(fufou_delay)
huoqubing:addSkill(fufou)
Fk:loadTranslationTable{
    ["ysch5_fufou"] = "服否",
    [":ysch5_fufou"] = "回合开始时，你可以指定一名其他角色，本回合每当你使用一张牌后，你可以弃置其一张牌；本回合结束时，其可以与你各摸X牌（X为你本回合弃置其牌数）。",
    ["#ysch5_fufou_delay"] = "服否",
    ["@ysch5_fufou-turn"] = "服否?",
    ["@ysch5_fufou_draw-turn"] = "服",
    ["#ysch5_fufou-choose"] = "是否尝试打服一名其他角色？",
    ["#ysch5_fufou-draw"] = "服否：是否与 %dest 各摸 %arg 张牌？",
    ["#ysch5_fufou-discard"] = "服否：是否弃置 %dest 一张牌？",
}
local huamulan = General:new(extension, "ysch5__huamulan", "wei", 4, 4, General.Female)--
Fk:loadTranslationTable{
    ["ysch5__huamulan"] = "花木兰",
    ["#ysch5__huamulan"] = "",
    ["designer:ysch5__huamulan"] = "yyuaN",
    ["cv:ysch5__huamulan"] = "未知",
    ["illustrator:ysch5__huamulan"] = "",
}
local rongbian = fk.CreateActiveSkill{
    name = "ysch5_rongbian",
    can_use = function (self, player, card, extra_data)
        return player:usedSkillTimes(self.name,Player.HistoryPhase) == 0 and Fk:currentRoom().current and not Fk:currentRoom().current:isNude()
    end,
    card_num = 0,
    target_num = 0,
    card_filter = Util.FalseFunc,
    target_filter = Util.FalseFunc,
    on_use = function (self, room, effect)
        local player = room:getPlayerById(effect.from)
        local cid = room:askForCardChosen(player, room.current, "he", "ysch5_rongbian", "#ysch5_rongbian-prompt")
        room:throwCard({cid}, "ysch5_rongbian", room.current, player)
        local hs = table.filter(player:getCardIds("h"),function (id)
            return #room:getCardsFromPileByRule(Fk:getCardById(id).name, 1, "allPiles") > 0
        end)
        if #hs > 0 then
            local name = Fk:getCardById(table.random(hs)).name
            local cards = room:getCardsFromPileByRule(name, 1, "allPiles")
            if #cards > 0 then
                room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonJustMove, "ysch5_rongbian", nil, true, player.id)
            end
        end
    end,
}
local rongbian_trigger = fk.CreateTriggerSkill{
    name = "#ysch5_rongbian_trigger",
    events = {fk.Damaged},
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill("ysch5_rongbian") and target == player and player.room.current and not player.room.current:isNude()
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local cid = room:askForCardChosen(player, room.current, "he", "ysch5_rongbian", "#ysch5_rongbian-prompt")
        room:throwCard({cid}, "ysch5_rongbian", room.current, player)
        local hs = table.filter(player:getCardIds("h"),function (id)
            return #room:getCardsFromPileByRule(Fk:getCardById(id).name, 1, "allPiles") > 0
        end)
        if #hs > 0 then
            local name = Fk:getCardById(table.random(hs)).name
            local cards = room:getCardsFromPileByRule(name, 1, "allPiles")
            if #cards > 0 then
                room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonJustMove, "ysch5_rongbian", nil, true, player.id)
            end
        end
    end,
}
rongbian:addRelatedSkill(rongbian_trigger)
huamulan:addSkill(rongbian)
local suying = fk.CreateTriggerSkill{
    name = "ysch5_suying",
    events = {fk.GameStart,fk.TargetSpecified},
    can_trigger = function (self, event, target, player, data)
        if player:hasSkill(self.name) then
            if event == fk.GameStart then
                return true
            else
                if table.find(player:getCardIds('h'),function(cid)
                    return Fk:getCardById(cid).name == "double_swords" end) and data.card and data.card.trueName == "slash" then
                    local target = player.room:getPlayerById(data.to)
                    return player:compareGenderWith(target, true)
                end
            end
        end
    end,
    on_trigger = function(self, event, target, player, data)
        if event == fk.GameStart then
            return self:doCost(event, target, player, data)
        end
        self.cancel_cost = false
        for _ = 1, #table.filter(player:getCardIds('h'),function(cid)
            return Fk:getCardById(cid).name == "double_swords" end) do
            if self.cancel_cost or not player:hasSkill(self, false, true) then break end
            self:doCost(event, target, player, data)
        end
    end,
    on_cost = function (self, event, target, player, data)
        if event == fk.GameStart then
            return true
        else
            if player.room:askForSkillInvoke(player, "double_swords") then
                return true
            end
        end
        self.cancel_cost = true
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        if event == fk.GameStart then
            for i = 1, 8, 1 do
                local id = room:printCard("double_swords", Card.Spade, 2).id
                if room:getCardArea(id) == Card.Void then
                    if i == 1 then
                        room:obtainCard(player,id,true,fk.ReasonJustMove,player.id,self.name)
                    else
                        table.removeOne(room.void, id)
                        table.insert(room.draw_pile, math.random(1, #room.draw_pile), id)
                        room:setCardArea(id, Card.DrawPile, nil)
                    end
                end
            end
            room:syncDrawPile()
            room:doBroadcastNotify("UpdateDrawPile", tostring(#room.draw_pile))
        else
            room:broadcastPlaySound("./packages/standard_cards/audio/card/double_swords")
            room:setEmotion(player, "./packages/standard_cards/image/anim/double_swords")
            local to = player.room:getPlayerById(data.to)
            if to:isKongcheng() then
                player:drawCards(1, self.name)
            else
                local result = room:askForDiscard(to, 1, 1, false, self.name, true, ".", "#double_swords-invoke:"..player.id)
                if #result == 0 then
                    player:drawCards(1, self.name)
                end
            end
        end
    end,
}
local suying_maxcards = fk.CreateMaxCardsSkill{
    name = "#ysch5_suying_maxcards",
    exclude_from = function(self, player, card)
        return player:hasSkill(suying.name) and card.name == "double_swords"
    end,
}
suying:addRelatedSkill(suying_maxcards)
huamulan:addSkill(suying)
Fk:loadTranslationTable{
    ["ysch5_rongbian"] = "戎弁",
    [":ysch5_rongbian"] = "出牌阶段限一次，或当你受到伤害后，你可以弃置当前回合角色一张牌，从游戏内获得一张随机手牌的同名牌。",
    ["#ysch5_rongbian-prompt"] = "戎弁：弃置当前回合角色一张牌",
    ["#ysch5_rongbian_trigger"] = "戎弁",
    ["ysch5_suying"] = "朔缨",
    [":ysch5_suying"] = "游戏开始时，将8张【雌雄双股剑】加入游戏，你获得其中一张，其余洗入牌堆。上述牌在你手牌中时不占上限，且同样提供武器技能。",
}
return extension--